JSON formatter and syntax validator

Check JSON syntax, add 2-space, 4-space or Tab indentation, or compact the input to one line. Copy or download the result after it passes validation.

Input is processed in this browser. The formatter keeps number tokens, key order and string escapes as written; it does not repair invalid JSON.

Your JSON is processed in this browser. It is not uploaded or saved automatically. Reloading the page clears it.

Input is limited to 100,000 UTF-16 code units, 64 levels of nesting and 5,000 values. Run it again after changing the input or indentation.

How to format JSON

  1. Paste your JSON and choose 2 spaces, 4 spaces or Tab for indentation.
  2. Select Validate and format to check the syntax and add indentation. To remove formatting whitespace, select Compact to one line. Whitespace inside strings stays as written.
  3. If the input is invalid, use the line and column hint to find the issue, correct it yourself and run the formatter again. Copy or download the result after it passes validation.

What does the formatter preserve?

It changes formatting whitespace outside strings. Large integers, negative zero, exponent notation, string escapes, key order and duplicate keys remain in their original form. Numbers are not converted to JavaScript numeric values first.

Duplicate keys remain in the output, but different programs may keep only one value or handle the duplicates differently. Valid JSON syntax also does not confirm that an API or JSON Schema accepts the data.

The parser accepts standard JSON values: objects, arrays, strings, numbers, booleans and null. It rejects comments, single-quoted strings, trailing commas, NaN and Infinity.

Input is limited to 100,000 UTF-16 code units, 64 nested object or array levels and 5,000 values. Objects and arrays each count as a value. An emoji outside the Basic Multilingual Plane uses two UTF-16 code units. Formatted output is limited to 2,000,000 code units; use less indentation or compact to one line if it exceeds the limit. Error lines and columns start at 1. A tab counts as one column, as does each UTF-16 code unit, so the displayed column may differ from the visual position of some characters.

Your input is not uploaded or saved automatically. Editing the input or changing indentation clears the previous result. Downloading creates a separate JSON file and does not overwrite the source file.

Related text tools

To compare changes between two versions, usetext comparison. To check text length, useword counter.

Format JSON, Find Errors, and Preserve Values

Back to tool

Format a response so you can scan its structure

A one-line API response is hard to scan when you need to check which fields belong inside an object or array. Paste the JSON, choose 2 spaces, 4 spaces or Tab, and select Validate and format. The formatter adds line breaks and indentation outside strings so the nesting is easier to follow.

For example, {"name":"Mina","active":true} becomes a multi-line object with name and active on separate lines. Choosing Compact to one line removes formatting whitespace between tokens. A space inside a value such as "Mina Lee" stays there because it is part of the string, not indentation.

The input can be an object or array, or a single string, number, boolean or null value. Formatting changes how the JSON is laid out. It does not rename fields, change values or decide whether the data is useful to the receiving service.

Use the line and column hint to find syntax errors

A validator can point to where parsing stopped, but it cannot know what you intended to write. The reported location may be just after the original mistake. Start there, then check the preceding value, comma, colon and quotation marks.

In this example, a comma is missing between the status and data fields. The error points to the opening quote of data at line 1, column 16. Add the comma yourself, then run the formatter again. The corrected JSON and its compact result are shown below.

Object keys and strings need double quotes. JSON also rejects comments, single-quoted strings, trailing commas, NaN and Infinity. A leading zero in a number is invalid, so use a string such as "001" only if the receiving API expects that identifier to be a string.

A missing comma and the corrected result
StageJSON
Invalid input{"status":"ok" "data":{"id":1042,"active":true}}
Corrected input{"status":"ok","data":{"id":1042,"active":true}}
Compact result{"status":"ok","data":{"id":1042,"active":true}}

Valid JSON does not guarantee an API accepts it

Syntax validation answers whether the text follows JSON grammar. It does not check required fields, field names, value types, date formats or application rules. For example, {"active":"true"} and {"active":true} are both valid JSON, but the first value is a string and the second is a boolean. If an endpoint expects a boolean, formatting cannot change a quoted string into one.

Duplicate object keys need extra care. This formatter preserves every occurrence in its original order and does not choose a value. RFC 8259 recommends unique names; it also notes that receiving software can behave unpredictably when names repeat. Check the source data and the API contract instead of treating a successful format as a decision about which value is correct.

Number tokens and string escapes stay as written

The formatter works from JSON tokens rather than converting the document through JavaScript numbers. It preserves the spelling of numbers, key order, duplicate keys and escapes inside strings. For example, the number 9007199254740993 remains those same digits in the output, and 1e3 is not rewritten as 1000.

That is a property of this formatter's output, not a promise about the next program that reads it. A receiving system may use a numeric type with a smaller exact range or different precision. RFC 8259 describes the interoperability limits of commonly used double-precision numbers. If a value is an identifier, use a JSON string only when the receiving contract defines it as a string; do not quote every number as a workaround.

Whitespace outside strings is formatting and can be removed in compact mode. Characters inside strings are part of the value, so the formatter keeps spaces and escape spellings such as "\u0061\n" rather than decoding and rewriting them.

Examples of token spellings retained by the formatter
Input tokenOutput tokenWhat stays the same
90071992547409939007199254740993Every digit of a large integer
1e31e3Exponent notation
-0-0Negative zero
"a b""a b"The space inside the string

Work within the input and output limits

One input can contain up to 100,000 UTF-16 code units, 64 nested object or array levels and 5,000 values. Objects and arrays each count as a value. A supplementary character such as many emoji uses two UTF-16 code units, and a combined emoji can use more. The formatted output can be up to 2,000,000 UTF-16 code units. If formatting exceeds that limit, reduce the indentation or compact the JSON; compact output is bounded by the smaller input limit.

Error lines and columns start at 1. A tab counts as one column, and the column calculation counts UTF-16 code units. A supplementary character may therefore count as two columns even when it looks like one symbol. Use the location to narrow down the area, then inspect the text around it.

Your JSON stays in the browser and is not uploaded or saved automatically. Reloading clears the page. Editing the input or changing indentation clears the previous result, so run it again before copying or downloading. A download creates a separate JSON file and does not overwrite your source file.

When comparing two versions, first format both with the same indentation. The text comparison tool can show line changes, but it does not decide whether two JSON documents mean the same thing. Use the word counter when you need a text length rather than a syntax check.

Questions about JSON formatting

Does the formatter fix invalid JSON?

No. It reports a syntax error and, when available, its line and column. You need to correct the input yourself and run it again. The tool does not add a missing comma, quote or value.

Why did compact mode keep a space?

Compact mode removes whitespace between JSON tokens, not characters inside a string. A space in "Mina Lee" is part of the value and remains in the result.

Will the output preserve duplicate keys?

Yes. The formatter keeps repeated keys and their order in the output. The program that later reads the JSON may treat them differently, so check the receiving system's behavior and remove unintended duplicates at their source.

Does a successful check mean the API will accept the JSON?

No. It means the input follows the syntax accepted by this formatter. Check the API's required fields, value types and other rules separately.

References

Updated