common JSON errors · 6 min read
Common JSON Errors and How to Fix Them With a Formatter
Learn how to diagnose common JSON syntax problems—quotes, commas, brackets, escaping, and data types—using a formatter and validator instead of guessing through minified data.
JSON is easy to read when it is formatted and surprisingly difficult to debug when it is compressed into one long line. A missing quote, an extra comma, or a closing bracket in the wrong place can cause an API request, configuration file, or JavaScript operation to fail even though the data looks almost correct at first glance.
This guide focuses on finding syntax problems, not on repeating a general introduction to JSON. If you already have a payload that needs inspection, paste a safe, non-sensitive copy into the Adawati Plus JSON Formatter & Validator to make the structure visible and check whether the text is valid JSON.
What Valid JSON Looks Like
JSON represents data with objects, arrays, strings, numbers, booleans, and null. RFC 8259 defines the JSON data-interchange format and its syntax 1. A basic object might look like this:
{
"name": "Sara",
"active": true,
"roles": ["editor", "author"]
}
The structure is simple, but JSON is strict about punctuation and string quoting. JavaScript object syntax and JSON look similar, yet not every JavaScript object literal is valid JSON.
Error 1: Using Single Quotes for Strings
This is invalid JSON:
{'name': 'Sara'}
JSON strings use double quotation marks. The valid version is:
{"name": "Sara"}
This mistake is common when data is copied from code written in a language that allows single-quoted strings.
Error 2: Trailing Commas
A trailing comma after the final object member or array item is not valid in standard JSON.
Invalid:
{
"name": "Sara",
"active": true,
}
Valid:
{
"name": "Sara",
"active": true
}
If a parser reports an error near a closing brace or bracket, inspect the item immediately before it.
Error 3: Missing Commas Between Members
This fails because two members are placed next to each other without a separator:
{
"name": "Sara"
"active": true
}
A formatter may be unable to beautify the text until the syntax is corrected, but a validator can help point you toward the location where parsing stopped.
Error 4: Mismatched Braces and Brackets
Objects use {} and arrays use []. In nested data, it is easy to close the wrong structure.
For example:
{
"users": [
{"name": "Sara"},
{"name": "Omar"}
}
]
The final ] should be } because the outermost structure is an object. Formatting the payload with indentation makes this type of mismatch much easier to see.
Error 5: Unescaped Quotes Inside a String
If a string contains a quotation mark, it must be escaped.
Invalid:
{"message": "He said "hello""}
Valid:
{"message": "He said "hello""}
Escaping problems are common when HTML, SQL snippets, user-generated text, or other encoded content is inserted into JSON manually.
Error 6: Treating Numbers and Booleans as Strings
This example is syntactically valid:
{"count": "10", "active": "true"}
But the values are strings, not a number and boolean. If the receiving API expects numeric and boolean types, the request may fail validation or behave incorrectly even though the JSON parser accepts it.
The typed version is:
{"count": 10, "active": true}
This is an important distinction: valid JSON does not guarantee valid business data. A formatter checks structure; the API documentation defines what each field is supposed to mean.
Error 7: Duplicate Object Names
RFC 8259 notes that object names should be unique for interoperable behavior 1. Some parsers keep the last duplicate value, others behave differently. Avoid payloads such as:
{"status": "draft", "status": "published"}
A syntax validator may still accept this text, so you need a semantic review in addition to syntax checking.
A Practical Debugging Workflow
1. Preserve the raw response
Keep a copy of the exact request or response that failed. Do not immediately edit the only copy because the original error context may matter.
2. Remove secrets before using an online tool
API keys, access tokens, passwords, personal records, and confidential customer data should not be pasted into third-party tools unless your organization explicitly permits it. Replace sensitive values with harmless placeholders while preserving the same JSON structure.
3. Format and validate
Use the JSON Formatter & Validator to indent the payload and check its syntax. Follow the first parsing error before trying to fix ten things at once; later errors may be a consequence of the first broken delimiter.
4. Compare with the API schema or documentation
After the text becomes valid JSON, verify field names, types, required values, and nesting. MDN’s JSON guide provides a useful overview of working with JSON in JavaScript and web applications 2.
5. Test the smallest payload
If an API request still fails, reduce it to the minimum required fields and add optional sections back gradually. This isolates whether the problem is syntax, a field value, authentication, or application logic.
Formatting Is Not the Same as Validation
Pretty-printing adds indentation and line breaks. Validation checks whether the text follows JSON grammar. A formatter can make valid data easier to read, but it cannot tell you whether an email address is real, a product ID exists, or an API token is authorized.
Likewise, a minified one-line JSON document can be perfectly valid. Whitespace is for readability; punctuation and data types determine the structure.
Conclusion
Most JSON syntax failures come from a short list of issues: wrong quotes, missing or trailing commas, mismatched brackets, bad escaping, and confusion about types. Format the data so the nesting is visible, validate the syntax, then compare the valid payload against the API’s expected schema. That sequence is faster and safer than editing minified data by eye.
Frequently Asked Questions
Is formatted JSON different from minified JSON?
The data can be equivalent. Formatting adds whitespace for readability, while minification removes unnecessary whitespace. Both can be valid JSON.
Can a JSON validator detect a wrong API value?
Only if the value breaks JSON syntax. A valid but incorrect customer ID, enum value, or token must be checked against the application or API rules.
Can JSON contain comments?
Standard JSON does not define JavaScript-style comments. Configuration systems that allow comments are usually using an extended format rather than strict JSON.
