Validate JSON Syntax: What a Check Proves and What It Can Change

How JSON syntax validation works, what formatting and auto-repair can silently change, and how to keep JSON valid when copying or sharing it.

Checking whether text is valid JSON answers one narrow question: does it parse under the JSON standard (RFC 8259, also published as ECMA-404)? A passing result does not mean the data is correct, complete or shaped the way a program expects. This review is based on the specification and on documented behavior of common parsers. No specific validator product was tested, so tool-specific claims are framed as things to confirm in that tool's documentation.

The short answer: when a syntax check is the right step

A validate-only check is safe for almost any use because it reads the text without changing it. Its main benefit is catching a broken document before it reaches a program, usually with a line and column pointing at the first error. The decisive tradeoff appears when a tool also formats, repairs or re-serializes the input, because those steps can alter values, not just layout. Keep the original text untouched in three cases: when exact bytes matter (signatures, hashes, checksums, clean diffs), when numbers must survive at full precision, and when the file is meant to be a commented configuration format rather than strict JSON.

What a JSON syntax validator checks

  • Strings and object keys use double quotes. Single quotes and unquoted keys are invalid.
  • The literals true, false and null are lowercase. True, FALSE and None are invalid.
  • No trailing comma after the last item in an array or object.
  • No comments of any kind.
  • Numbers have no leading zeros (012), no leading plus sign, no hexadecimal, and at least one digit on each side of a decimal point (.5 and 5. are invalid).
  • NaN and Infinity are not valid JSON values.
  • Control characters such as a raw tab or newline inside a string must be escaped (\t, \n).
  • Whitespace between tokens is limited to space, tab, line feed and carriage return.
  • Under RFC 8259 any value may sit at the top level, including a bare string or number; some older tools still expect an object or array.

Syntax validation does not check types, required fields or allowed values; that is the job of a schema check such as JSON Schema. It also usually does not flag duplicate keys. The standard says object names should be unique but leaves behavior with duplicates unpredictable, and many parsers silently keep the last value.

Example: common errors and a corrected version

{
  'name': "Ada",
  "active": True,
  "tags": ["a", "b",],
  // added later
  "count": 012
}

This input has five problems: a single-quoted key, a capitalized True, a trailing comma inside the array, a comment, and a number with a leading zero. A validator normally stops at the first error, so expect to fix and re-check several times.

{
  "name": "Ada",
  "active": true,
  "tags": ["a", "b"],
  "count": 12
}

The last fix required a judgment call. If 012 was a code where the leading zero matters, such as a US ZIP code fragment or an ID, the correct repair is the string "012", not the number 12. Automatic repair tools cannot know which was intended, so treat their output as a suggestion to review rather than a finished result.

What validation, formatting and repair actually change

Operation | What changes in the stored text | Risk to meaning
Validate only | Nothing | None, but the verdict depends on how strict the parser is
Pretty-print or minify by adjusting whitespace | Whitespace between tokens only | None, provided whitespace inside strings is left alone
Parse and re-serialize | Number spelling, escapes, key order, duplicate keys | Values can change without warning
Auto-repair | Quotes, commas and sometimes value types | Based on guesses about intent

Many formatters work by parsing the input into data and writing it back out, which is a re-serialization rather than a whitespace edit. In JavaScript, JSON.stringify(JSON.parse(input)) turns the first line below into the second:

{"price": 1.10, "id": 9007199254740993, "a": 1, "a": 2}
{"price":1.1,"id":9007199254740992,"a":2}

Three changes happened. 1.10 became 1.1, which is numerically equal but different text, which matters for hashes, diffs and any system that treats the digits as meaningful. The ID changed value because JavaScript stores numbers as IEEE 754 doubles, which cannot represent every integer above 2^53; the standard itself warns about this interoperability limit. The duplicate key collapsed to its last value. Escapes can also be rewritten, for example \u00e9 becoming é or the reverse. The string value is the same but the bytes differ. When any of this matters, pass large IDs as strings, or use a tool documented to preserve the original text.

Strictness differs between tools

Passing one validator does not prove a document is standard JSON. Python's json module accepts NaN and Infinity by default, including through python -m json.tool, so it can approve a file that a strict parser rejects. Byte order marks are another split. RFC 8259 says senders must not add one and parsers may ignore one, but JavaScript's JSON.parse throws if the string begins with a BOM. Escaped unpaired surrogates, such as a lone \ud800, are allowed by the grammar but handled inconsistently. Related formats like JSON5, JSONC and JSON Lines are not JSON. A strict validator will correctly reject comments in a JSONC file, and a JSON Lines file must be checked one line at a time. The most reliable check uses the same parser that will consume the data.

python3 -m json.tool data.json > /dev/null && echo valid
node -e "JSON.parse(require('fs').readFileSync('data.json','utf8'))" && echo valid

Both commands run locally and exit with an error and a position message if parsing fails. The Python version inherits the NaN and Infinity leniency described above. The Node version reads the file without stripping a BOM, so it will reject files that begin with one.

Will it stay valid after copying or sharing?

  • Curly quotes: some word processors, note apps and messaging tools replace straight double quotes with typographic ones, which breaks every string.
  • Non-breaking spaces: text copied from web pages or rich-text editors can carry U+00A0. Outside strings it makes the document invalid. Inside strings it silently changes the value.
  • Zero-width characters: these are invisible in most editors but still count as characters, so a validator may report an error at a spot that looks clean.
  • Line wrapping: if a long string is broken across lines by hand or by a mail client, the raw newline inside the string is invalid.
  • Truncation: message length limits or preview panes can cut a document off, leaving unclosed brackets.

When an error points at a position that looks correct, turn on your editor's display of invisible characters or inspect the bytes in a hex view. To share JSON with less risk, send it as a file or inside a code block, which most platforms leave unformatted. Confirm this for the specific destination rather than assuming it.

Pretty-printing affects readability, not validity. Minified JSON on a single line is hard to read, edit or compare in a diff. Consistently indented JSON is easier to review, as long as every contributor uses the same formatter so that diffs show real changes. How screen readers announce punctuation-heavy JSON depends on the screen reader and its verbosity settings, and that was not tested for this review. If the audience needs to understand the data rather than parse it, provide a plain-text equivalent alongside the raw JSON, such as a short prose summary or a table of field names and values.

Privacy when using an online validator

Pasting JSON into a web-based validator may send it to a server. A tool's design or a label such as 'runs in your browser' does not establish how it handles data. Only its documented policy, or your own inspection of its network activity, can do that. For API keys, tokens or personal data, use a local command like those above, or confirm the tool's documented behavior first.

Gaps in this review

No named online validator, editor plugin or repair tool was evaluated, so there are no product comparisons, accuracy rates or speed measurements here. Parser-specific statements are limited to documented behavior of Python's json module and JavaScript's JSON.parse. Clipboard behavior of specific apps and screen reader output were not tested. Results from the parser your system actually uses should take priority over any general guidance.