Mita SchoolStudent Innovation Lab

JSON DEVELOPER GUIDE MITA-001

JSON vs JavaScript objects: what changes?

They look similar in a code editor, but JSON is a text format and a JavaScript object is a value in a running program. That difference matters when you exchange data.

JSON is text; a JavaScript object is a runtime value

A JSON document is a sequence of characters that follows a data format. A JavaScript object exists in a running program and can hold values that JSON cannot represent. When an API sends a JSON response, your application normally receives text or bytes and parses them into runtime values.

The similar punctuation is the source of much confusion. You can recognize curly braces and colons in both formats without being able to copy arbitrary JavaScript source into a strict JSON validator.

The key syntax differences

FeatureStandard JSON textJavaScript object literal
Property namesDouble-quoted stringsMay use identifier names, quoted strings, or computed names.
String delimitersDouble quotesMay use single quotes, double quotes, or template literals.
Trailing commasNot allowedAllowed in many literal forms.
CommentsNot allowedAllowed in source code.
Methods and functionsNot representableCan be properties of an object.
undefined, NaN, InfinityNot JSON valuesExist in JavaScript.
Date or Map objectsNo native representationSupported as runtime objects.

The first block is JavaScript source:

const student = {
  name: 'Ada',
  active: true,
};

The equivalent JSON text contains no variable declaration and uses double quotes:

{
  "name": "Ada",
  "active": true
}

Use JSON.parse and JSON.stringify for the boundary

JSON.parse reads valid JSON text and creates the corresponding JavaScript value. JSON.stringify serializes a supported JavaScript value into JSON text.

const text = '{"name":"Ada","active":true}';
const student = JSON.parse(text);

console.log(student.name); // Ada

const readable = JSON.stringify(student, null, 2);
console.log(readable);

The third stringify argument controls indentation. It helps readability, but it does not validate your application’s expected fields. A malformed input document throws a syntax error during parsing; an object with the wrong business fields may still serialize successfully.

Never evaluate JSON as code. Use a JSON parser for data. Avoid eval and dynamic function construction when reading documents from an API or an untrusted source.

Some runtime values change during serialization

JSON has a smaller set of types than JavaScript. Plan how special values should cross your API boundary instead of relying on incidental serialization behavior.

JavaScript valueTypical JSON.stringify behavior
undefined in an object propertyThe property is omitted.
undefined in an arrayThe position is serialized as null.
NaN or InfinitySerialized as null.
A Date instanceNormally serialized as an ISO date string through its toJSON method.
A BigInt without custom handlingThrows a TypeError.
A circular referenceThrows a TypeError.

Functions and symbols also need care. A replacer or custom toJSON method can change the result further. Define a documented representation for dates, special numeric values, and domain-specific objects when another system must interpret them.

Why large numbers can change in a formatter

JavaScript’s ordinary Number type cannot exactly represent every long integer. Converting 9007199254740993 to a Number can round it before a formatter has a chance to print the original digits.

Mita’s formatter keeps the original JSON tokens rather than using an ordinary object round trip for its output. This preserves long IDs, decimal spelling, repeated names, and exponent spelling. It also warns about values that can be problematic in a consuming parser.

That is a display and formatting guarantee, not a guarantee about every application reading the document. For identifiers, a documented string representation is often suitable. For calculations requiring greater precision, choose a matching numeric representation and library at both ends of the system.

Choose the right check for the job

Use JSON Formatter & Validator to inspect grammar and layout. Use your code’s tests and API contract to verify required fields and types. Use a separate JSON Schema validator when you need schema-based checks. These checks complement one another: readable text does not automatically mean correct application data.

Put the explanation to work. Open the tool to format, inspect, or validate your document.

Open JSON Formatter →
Built for Mita Innovation Lab · MITA-001 · Web DevelopmentRelease 1.0 · October 2026