EVERYDAY FILE TOOLS / FIELD GUIDE

Format JSON without changing values

Formatting should make a file easier to read. It should not quietly change an order number, collapse two competing values or rewrite a price. These checks help you separate presentation from the data underneath it.

Keep long identifiers intact

Consider this small record:

{"order":9007199254740993,"price":12.50}

The order number is an identifier. A formatter that first converts every number into an ordinary JavaScript number can change that identifier before it prints anything. A parser can also print the price as 12.5. The second spelling may represent the same numeric value, but it is still a change to the text you supplied.

Our formatter keeps each number token as written. The output retains both 9007199254740993 and 12.50. This does not make those numbers safe in every downstream application: a receiving application can still interpret or round them. If your data contract uses strings for identifiers, keep them as strings at the source. Formatting alone does not change that contract.

Readable and compact are two views of the same structure

Readable output adds two spaces per level and places members on separate lines. Compact output removes optional whitespace outside strings. Neither option sorts object names, changes array order or rewrites string escapes.

{"note":"  Leave these spaces  ","line":"first\nsecond"}

The spaces within the note belong to the value. So does the escaped line break in the second string. Removing whitespace everywhere with a regular expression would damage this data. Use a formatter that recognises strings and their escape sequences.

Resolve repeated names before formatting

{"delivery":"standard","delivery":"express"}

Which delivery should the receiving system use? Different parsers can handle repeated names differently. This tool stops and points to the repeated name, leaving you to choose the intended value in the original source. Names written with equivalent Unicode escapes also count as the same name. Reusing a name in two different nested objects is fine; the conflict is within a single object.

Read the first error before changing several things

Object names and strings need double quotation marks. Names and values are separated by a colon. Values within an array or object are separated by commas, with no comma after the last value. Comments, single-quoted strings, undefined and a JavaScript expression are not accepted JSON here.

The error gives a line and column in your input. It can point just after the underlying mistake—for example, a missing comma may only become apparent at the next value. Check the indicated area and the preceding character, make one correction, then run the formatter again. It never fills in a missing value or executes your text.

Use the original as your recovery point

Paste a copy and keep the source file. Download produces a separate formatted-data.json file. Compare a long identifier, a price, an array and a string with escapes before replacing anything in another system. Clear or refresh discards this page's working copy; there is no account history to restore it from.

The tool accepts up to 64 KB of UTF-8 text, 10,000 values and 64 levels of nesting. It rejects unpaired Unicode surrogates for interoperability. These are this tool's limits, not claims that every larger or differently encoded document is invalid JSON.

Open the JSON formatter →

Reference: JSON format specification, RFC 8259. The examples and tool behaviour above are specific to this service.