JSON validation, formatting, and JSON Lines
What a validator actually checks, why formatting is safe, and when JSON Lines is the right shape for your data.
JSON is simple enough to write by hand and unforgiving enough that a single trailing comma breaks an entire pipeline. Working with it comfortably comes down to four separate jobs: checking syntax, formatting for humans, transforming structure, and choosing the right shape on disk. This guide covers each, along with the edge cases that cause real bugs.
What makes JSON valid
JSON has six value types: strings in double quotes, numbers, booleans (true and false), null, arrays, and objects with double-quoted keys. Much of what JavaScript allows is not JSON:
- Comments (
//and/* */). Configuration formats like tsconfig.json use JSONC, which allows comments, but strict parsers reject them. - Trailing commas after the last item in an array or object.
- Single-quoted strings and unquoted keys.
NaN,Infinity,undefined, and hexadecimal numbers.- Raw line breaks or tabs inside strings. Use
\nand\t. - “Smart” curly quotes, which sneak in when JSON is pasted through a word processor or chat app.
The JSON validator checks strict syntax without changing your document and, for valid documents, reports the root type, the number of values, and the nesting depth.
Numbers that silently change
JSON itself puts no limit on numbers, but JavaScript, and many other parsers, store them as 64-bit floating point. Integers above 9,007,199,254,740,991 (2⁵³ − 1) cannot all be represented exactly, so 9007199254740993 is read as 9007199254740992 without any error. Database IDs and snowflake IDs from social platforms often exceed this, which is why their APIs also send IDs as strings. The validator flags such numbers. The fix is to quote large identifiers at the source.
Validation is not schema validation
A syntax check answers “is this parseable?”. It does not answer “does this match what my API expects?”: required fields, types, allowed values, and formats. That is the job of JSON Schema and your application’s own validation. Check syntax first, since a schema validator cannot work on a document it cannot parse, and then validate the structure against a schema in your code or CI.
Formatting for humans
Format JSON adds consistent indentation and line breaks, which turns a minified API response into something you can read and review. Formatting only changes whitespace between tokens, but be aware of two details. If a key appears twice, only its last value is kept after parsing. Very large integers are subject to the precision limit above. Keep the original file when exact bytes matter.
Sort JSON keys is a separate, deliberate change: it orders keys alphabetically at every level while keeping arrays in order. Sorted files diff cleanly in version control.
Transforming structure
- Flatten JSON turns a nested document into path records, which are easy to search, diff, or edit in a spreadsheet. Unflatten JSON rebuilds the exact structure, including empty objects and arrays.
- Merge JSON layers one document over another, deep or shallow, with an explicit rule for arrays.
- Compare JSON reports structural differences by path, ignoring key order and whitespace. See the comparing and merging guide.
- The JSON tree viewer lets you explore large documents branch by branch and export exactly the value you select.
When JSON Lines is the right shape
JSON Lines, also called JSONL or NDJSON, stores one complete JSON value per line:
{"id":1,"ok":true}
{"id":2,"tags":["a","b"]}
nullA reader can process one line at a time without loading the whole file, and a writer can append a record by adding a line. That makes it the natural format for logs, data exports, streaming imports into data warehouses such as BigQuery, and batch requests to AI APIs. Regular JSON arrays remain better for configuration and API responses that are read as a whole.
Each record must fit on one line, so pretty-printed objects spanning several lines are not valid JSON Lines. That mismatch is the most common cause of errors in the JSON Lines converter, which converts in both directions and reports the exact failing line. Blank lines are rejected by default, because they usually mean a record went missing.
Practical limits
The JSON tools accept up to 1,000,000 characters. Live previews pause on very large inputs, and running the tool still processes the full supported document. Everything is parsed in your browser, so API responses containing personal data or tokens are not uploaded anywhere.
