To know whether JSON will work, check it in two stages: parse it to confirm the text follows JSON syntax, then validate it against the receiving application’s requirements. A document can be valid JSON yet still have missing fields, incorrect types, or values another system handles differently.
What does valid JSON look like?
JSON is a lightweight, text-based format for exchanging structured data. Its grammar is defined by RFC 8259. JSON can represent objects, arrays, strings, numbers, the lowercase literals true and false, and null.
As an Amazon Associate I earn from qualifying purchases.
- Objects use braces,
{}, to hold name-and-value pairs. Each name is a string followed by a colon and a value. - Arrays use brackets,
[], to hold an ordered sequence of values. - Strings and object names use double quotes. Required characters, including quotation marks, reverse solidus characters, and control characters, must be escaped.
- Numbers use JSON’s decimal syntax, which permits fractions and exponents but not leading zeros before nonzero digits.
For example, this is a JSON object containing strings, a number, a boolean, an array, and a null value:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →{
"name": "Ari",
"items": ["book", "lamp"],
"active": true,
"score": 12.5,
"note": null
}
JSON is not the same as JavaScript object-literal syntax. Standard JSON has no comments, single-quoted strings, unquoted object names, trailing commas, undefined, NaN, or infinity values. Some parsers accept such extensions, but their acceptance does not make the text standard JSON.
#1 Best Overall
RFC 8259 allows a JSON text to contain any JSON value, including a top-level string, number, boolean, or null. An object or array at the top level may be the more conservative choice when exchanging data with older or constrained systems.
How do you write JSON reliably?
- Decide what each value represents. Use objects for named properties, arrays for ordered lists, strings for text, numbers for numeric values, booleans for true-or-false values, and
nullwhen the data calls for that explicit value. - Quote names and text with double quotes. Put a colon between each object name and value. Separate members and array elements with commas, but do not put a comma after the final item.
- Match the structure. Close every opening brace and bracket with its corresponding closing character. Whitespace may appear around structural characters.
- Use only JSON values. Do not add comments or rely on JavaScript-only values such as
undefinedorNaN. - Keep object names unique. Repeating a name in one object can produce different outcomes across implementations.
How do you check whether JSON is valid?
Parse it with a JSON parser rather than relying on visual inspection. Parsing catches syntax problems such as missing commas, mismatched braces, malformed escapes, or incorrectly quoted names. It does not establish that the data meets an application’s requirements.
Check JSON from the command line with Python
Python’s standard-library JSON tool can parse a file and pretty-print it:
python -m json.tool input.json
Replace input.json with the path to your file. If parsing succeeds, the tool prints formatted JSON. If it fails, Python reports a JSONDecodeError with the error position, line, and column, which can help locate the syntax problem. See the Python 3.12.15 JSON documentation for the module’s behavior.
Rank #3
A successful parse means the parser accepted the text; it does not prove every other parser will interpret it identically or that the receiving application will accept its contents.
How do you validate JSON against application requirements?
After parsing, check the data against the contract expected by the receiving application. That contract may require specific properties, types, or constraints. For example, an application may require a string property named email, even though JSON syntax itself does not require that property to exist.
JSON Schema is a declarative way to describe and validate JSON document structure, constraints, and data types. Use a schema that matches the intended contract and the schema version supported by your validator. A schema check answers a different question from parsing: whether the parsed value has the required shape and constraints, rather than whether its text is grammatical JSON.
Why is my JSON invalid?
| Symptom | Likely cause | What to check |
|---|---|---|
| “Expecting property name enclosed in double quotes” | An object name is unquoted or uses single quotes. | Use a double-quoted string for every object name. |
| A parser fails near the end of an object or array | A comma or closing bracket may be missing, or a trailing comma may be present. | Check that each opening brace or bracket is matched and that commas separate entries only—not the last entry from the closing character. |
| The text works locally but fails in another system | The local parser may accept nonstandard extensions, or duplicate names may be handled differently. | Use standard JSON syntax and remove duplicate names and nonstandard values. |
| Parsing succeeds, but the application rejects the data | The JSON is syntactically valid but does not meet the application’s structure or constraints. | Validate against the receiving contract or an appropriate JSON Schema. |
| A long numeric identifier changes after processing | A receiving system may not preserve the number’s full range or precision. | Check the number handling of every system in the data path; for identifiers that must be preserved exactly, consider representing them as strings if the application contract permits it. |
What can make valid JSON behave differently across systems?
Duplicate object names
Object names should be unique. RFC 8259 warns that behavior for duplicate names is unpredictable: an implementation might keep the last value, reject the object, or expose duplicates. Python 3.12.15’s standard-library decoder, for example, uses last-name-wins handling by default. Do not depend on one parser’s choice when another system may make a different one.
Nonstandard parser extensions
Python 3.12.15 documents default acceptance and output of NaN and infinities, even though those values are outside JSON’s number grammar. A successful local parse or serialization involving them therefore does not guarantee interoperable JSON. Prefer values conforming to RFC 8259 when data will cross system boundaries.
Number range and precision
JSON defines number syntax but does not require every implementation to preserve every possible numeric value with unlimited range and precision. RFC 8259 calls out interoperability limits, including common binary64-based handling. Large integers—particularly identifiers—can be risky if consumers use different numeric representations. Confirm the receiving systems’ behavior, or use strings for exact identifiers when the application’s contract allows it.
Size and nesting limits
Implementations may limit accepted document size, nesting depth, number range or precision, and string length. RFC 8259 does not guarantee that every parser accepts arbitrarily large or deeply nested input. If data approaches those limits, test it with the actual parsers and settings used by the systems that exchange it.
Free tools Windows power users keep installed
One-click scans. No signup required.
Quick Recap
What is the dependable JSON workflow?
- Write the data in standard JSON syntax. Use double quotes, lowercase literals, valid number syntax, commas between entries, and no comments or trailing commas.
- Parse it with a JSON parser. Fix syntax errors reported by the parser instead of assuming a document that looks right is valid.
- Validate its meaning. Check required fields, types, and constraints against the application contract or a suitable JSON Schema.
- Check interoperability. Avoid duplicate names and nonstandard values, and confirm that numeric precision, document size, and nesting depth are suitable for the intended systems.
- Test with the intended environment. Use the parser, its settings, and the schema version that the receiving application actually supports.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




