JSON

Why valid-looking JSON fails to parse

Work through common JSON syntax errors, preserve large identifiers, and choose formatting or comparison for the problem you actually have.

Open JSON Formatter

Start with the original response

Suppose an API request succeeds, but your client fails while parsing the response. Save a copy of the original response before editing it. A formatter can reveal syntax problems, but first check that you actually received JSON: a login page or HTML error response cannot be repaired by changing its indentation.

Paste a non-sensitive copy into JSON Formatter and select Format JSON. If parsing fails, use the reported position as a starting point. The underlying error may be immediately before it, such as a missing comma after the preceding property. Fix one problem at a time and retry.

An object literal is not always JSON

JavaScript source can contain single-quoted strings, unquoted property names, comments, and trailing commas. JSON cannot. A value copied from a console or a configuration format such as JSON5 may therefore need deliberate changes before a JSON parser accepts it.

In the first line below, the key is unquoted, the string uses single quotes, and the object has a trailing comma. The second line is valid JSON. Correct the source format rather than running a global quote replacement: an apostrophe inside a value should remain part of that value.

// JavaScript object literal, not JSON:
{mode: 'test',}

// JSON:
{"mode":"test"}

Check types and escapes before changing values

JSON supports objects, arrays, strings, numbers, true, false, and null. The string "false" is not the boolean false. An empty string is not null, and a missing property is different again. A successful parse only proves that the syntax is accepted; it does not establish that your application received the expected types.

A backslash inside a string begins an escape. Double the backslashes in a Windows path. Similarly, an actual line break inside a quoted string must be represented by an escape sequence. If a server serializes an object with a JSON library, let that serializer escape values rather than constructing JSON through string concatenation.

{
  "path": "C:\\Users\\demo",
  "message": "First line\nSecond line",
  "enabled": false
}

Preserve long identifiers as strings

A response can be syntactically valid while a downstream program loses numeric precision. JavaScript cannot represent every integer above 9,007,199,254,740,991 exactly. For example, parsing 9007199254740993 into a JavaScript number rounds it. Account IDs are usually labels, so exchanging them as strings often avoids an unnecessary numeric conversion.

Zentoolia’s formatter preserves numeric source tokens while changing whitespace, and the comparator compares decimal numbers without ordinary JavaScript rounding. Saved snippets and configurations do use parsed JavaScript values. Quote long IDs before saving them there. Do not assume that every application receiving a formatted file preserves the same precision.

{"accountId":"9007199254740993","attempts":2}

Choose the next check for your question

Format JSON when you need readable nesting, and minify when you need compact text with the same tokens. Use JSON Comparator when investigating changed fields between two responses: it ignores object-key order but treats array positions as meaningful. Use Text Diff when exact whitespace and line endings matter.

Finally, validate the parsed result against the consuming application’s contract. Check required fields, accepted values, ranges, and duplicate-key handling. A formatter cannot tell whether an order total is correct or whether a field named timeout uses seconds or milliseconds. Keep a small test fixture that captures the failure so it can be checked after the source is fixed.

Further reading

Browse all guides · Suggest a correction