Developer Tools guide

Find a JSON syntax error without changing the data’s meaning

A parser points at one character and says the JSON is invalid, but that character may be innocent. The real mistake is often a missing comma, quote or bracket earlier in the payload. Debugging JSON well means tracing structure first, then checking whether the valid result still means what the application expects.

Start at the reported position, then investigate backward

A parser often reports the point where it could no longer continue, not the original mistake. A missing comma can make the next key look wrong; an unclosed quote can make several later characters appear part of a string. Check the preceding property and the opening delimiter as well as the highlighted position.

JSON requires double-quoted property names and string values. It does not allow comments, trailing commas, single-quoted strings, undefined or JavaScript expressions. A JavaScript object literal copied from source code is not automatically JSON.

ProblemInvalid exampleCorrection
Unquoted key{name: "Ada"}{"name": "Ada"}
Trailing comma[1, 2,][1, 2]
Single quotes{'ok': true}{"ok": true}
Missing comma{"a": 1 "b": 2}{"a": 1, "b": 2}

Escaping is not decoration

A quote inside a JSON string must be escaped, and a literal backslash must also be represented correctly. File paths pasted from another language may already have one layer of escaping. Adding backslashes repeatedly without tracking that layer can produce valid but incorrect data.

If the payload is Base64-encoded or URL-encoded, decode the appropriate layer first. Do not feed encoded text into a JSON formatter and then alter it until the parser stops complaining; that loses the relationship to the source.

Valid JSON can still be the wrong request

Duplicate property names are particularly risky because parsing may retain only one value. Very large numeric integers can also lose precision in JavaScript. Keep identifiers as strings when the data contract calls for strings, and preserve an original copy before formatting.

A successfully formatted object may still omit required keys, contain an invalid date or fail a server’s schema. Validate against the actual API contract separately. SnakTool formats and parses JSON; it does not supply a universal schema validator or certify a request as safe.

Use a repeatable debugging sequence

Preserve the original payload before repairing it. Locate the reported error, inspect the previous token and separator, then trace back to the nearest opening quote, brace or bracket. Fix one structural issue and parse again instead of making several speculative edits at once.

Once parsing succeeds, compare key names, types and important values with the API contract. Pretty indentation helps humans see nesting, but formatting alone cannot validate business rules.

  1. Save the untouched input.
  2. Inspect the parser position and the token immediately before it.
  3. Match opening and closing quotes, braces and brackets.
  4. Fix one syntax problem and parse again.
  5. After syntax passes, validate types, required fields and application rules.

Duplicate keys and large numbers need special care

Duplicate object property names are risky because software can retain one occurrence, expose another or reject the input. Resolve the duplication at its source instead of relying on which value one parser happens to keep.

Very large integer identifiers can exceed JavaScript's exact integer range. If a data contract defines an identifier as a string, keep it as a string even when it contains only digits.

Repair the representation, not the intended value

A quote inside a JSON string needs escaping. A literal line break inside a quoted string is invalid; the two-character escape \n represents a newline. Adding or removing escape layers can change the value, so identify whether the input is JSON text or a JSON string containing more JSON.

Escapes and a double-encoded object
{"message":"She said \"Hi\"."}
{"message":"first line\nsecond line"}

"{\"ready\":true}" parses as a string.
{"ready":true} parses as an object.

References