Troubleshooting
How to Fix Invalid JSON: A Step-by-Step Debugging Workflow
Fix common JSON errors with a repeatable workflow for quotes, commas, escapes, duplicate keys, precision warnings, and schema failures.
Fix the first syntax error, validate again, and then check the data contract. A parse success does not prove the values mean what your application expects.
1. Keep the original and identify the input format
Before editing a failing payload, keep a local copy of the original. A rushed find-and-replace can remove evidence or change a value while making the document appear cleaner. Work on a small, redacted copy if the input includes sensitive information.
Check where the text came from. A JavaScript object literal, an HTML error page, a JSON string containing another document, and several JSON Lines records are different inputs. If the first character is a less-than sign, inspect the HTTP response before adding braces. If each line is a separate object, use a JSON Lines workflow rather than treating the entire file as one document.
This first decision prevents a common debugging loop: trying to repair valid data from the wrong format with a strict JSON formatter. Choose the appropriate importer, then validate its JSON result.
2. Fix the first syntax error, then validate again
A parser location is where it could no longer proceed, which can be after the actual mistake. Inspect the reported line and the preceding value. A missing comma between fields often becomes visible when the parser reaches the next field name.
Strict JSON uses double quotes for strings and property names, lowercase true, false, and null, and separators between values. Comments and trailing commas are outside its grammar. Do not globally replace apostrophes: an apostrophe inside a person’s name is ordinary string content, and a broad replacement could corrupt it.
In this example, the comma before the closing brace causes the failure. Removing that comma is a targeted correction. If another error remains, validate again and repeat. Avoid making several speculative edits before checking the result.
// Invalid JSON: trailing comma
{"name": "O'Connor", "active": true,}
// Corrected JSON
{"name": "O'Connor", "active": true}References: RFC 8259: JSON interoperability and syntax
3. Count the escaping layers
A JSON document and a JSON string that contains a document are not the same value. The first example below is an object. The second is a string whose decoded contents could be parsed as that object. Both can be valid, but an application expecting an object will not treat them alike.
Escaping problems often appear when JSON passes through a programming-language string, a log viewer, or another serialization layer. Find the layer that added escaping before removing it. Repeatedly unescaping arbitrary text can turn a literal backslash sequence into a different value.
For a Windows path, use a properly escaped JSON string rather than deleting backslashes until validation passes. In JSONSlate, use the string unescape tool only when the input is actually a quoted JSON string and you intend to decode that layer.
{"active":true}
"{\"active\":true}"
{"path":"C:\\exports\\daily.json"}4. Separate syntax, safeguards, and schema validation
A duplicate key or a number that may lose precision needs a different fix from a missing comma. JSONSlate conservatively refuses duplicate object keys and numeric inputs it cannot safely round-trip through its JavaScript number representation. Do not delete a duplicate or round an identifier just to silence the warning; confirm the intended value with the producer.
After parsing succeeds, a schema can still reject the document. For example, {"age":"42"} is valid JSON, but it fails a contract that requires age to be an integer. Decide whether the contract or the producer is wrong before changing the value. Converting every number-like string is particularly risky for identifiers such as "0042".
Read schema errors by path and keyword. A required error points to a missing property; a type error points to a present value with the wrong kind. Repair one mismatch and rerun validation against the same schema.
5. Verify the repair and prevent a repeat
Format the corrected document and compare it with the original. The diff should show the correction you intended, not unrelated value changes. Then run the consumer or its contract tests with the repaired fixture.
When you control the producer, generate JSON with a serializer instead of joining strings manually. Keep a minimal failing example as a regression fixture, including cases with quotes, newlines, empty arrays, and Unicode. A reliable repair ends at the place the malformed message was produced, so the next request does not recreate the same problem.
Put it into practice
Explore the examples in your own browser. Core JSON processing stays on your device.
Continue learning: JSON syntax reference · Common JSON errors.

