Fix JSON errors without changing what the data means

Formatting makes valid JSON easier to read, but broken input needs correction first. Keep the original and fix the nearest concrete syntax problem instead of rewriting the entire response at once.

1. Confirm that the input is JSON

Check that you copied a response body rather than its URL, an HTML login error or a JavaScript statement. Objects and arrays are not the only valid JSON values: strings, numbers, true, false and null are also possible, even if the receiving API requires an object.

2. Inspect quotes and separators

Property names and strings need double quotes. The reported position is where parsing could no longer continue, so the cause may be a missing comma just before it. Make a small correction and validate again.

Invalid inputCorrected inputChange
{'name':'Mina'}{"name":"Mina"}Use double quotes
{"count":2,}{"count":2}Remove the trailing comma
{"a":1 "b":2}{"a":1,"b":2}Separate properties
{"ok":True}{"ok":true}Use lowercase literals

3. Distinguish escapes from formatting whitespace

Inside a string, escape a double quote as \" and represent a literal backslash with two backslashes. Use \n for a newline within a string value. An actual newline between properties is formatting whitespace, while an unescaped newline inside a string is invalid.

Markdown backticks and explanatory prose copied with a code sample are not JSON either. When reporting a problem, replace credentials and personal values with invented data in the smallest example that still reproduces it.

4. Locate where numeric precision could be lost

This formatter retains number tokens such as 9007199254740993 and 1e3. A later program that reads them into ordinary JavaScript numbers can still lose precision for a large integer.

For exact identifiers, use strings if the data contract allows them. Formatting cannot restore digits already rounded by another system; compare the original response and the parsing or storage stages too.

5. Review duplicate names and schema separately

The formatter retains both entries in {"id":1,"id":2}. Downstream software may retain only the last value or reject the object. Resolve which value is intended in the source rather than asking formatting to choose.

After syntax passes, check required fields, types, allowed values and date formats against the API contract or JSON Schema. Syntactically valid data can still be rejected by its intended service.

6. Select output for the next reader

Use two or four spaces for human review and Minified for compact transfer. Minification does not delete spaces inside string values. Comparing the original and formatted text can reveal whitespace changes, although reformatting can produce many line-level differences.

References

Try the tools