JSON Formatter

Format, minify and validate JSON, or convert it to XML or CSV, directly in your browser. All processing happens locally; nothing is uploaded.

1
Output

Formatted JSON will appear here.

Paste JSON on the left and click Format, Minify, To XML or To CSV.

How to Use the JSON Formatter

  1. Paste your JSON into the Input box, or click "Sample" to load an example.
  2. Choose the indent (2 spaces, 4 spaces or Tab).
  3. Click "Format" for a readable version or "Minify" for a compact single-line version. If the JSON is invalid, the line and column of the problem are shown above the boxes.
  4. To change the format, click "To XML" or "To CSV". CSV works best with an array of objects, such as a list of records.
  5. Use "Copy" or "Download" above the Output box to take the result with you.

What Happens When You Click Format or Minify

Your text is first parsed with the browser's built-in JSON parser. If parsing succeeds, the resulting data is written back out as text. Format writes it with line breaks and the indent size you picked, placing every object property and every array item on its own line. Minify writes the same data with no spaces or line breaks at all.

Because the output is rebuilt from the parsed data rather than edited in place, it is always valid JSON. The same step also means a few details of your original text are not preserved, as explained below.

Example

Input pasted from an API response:

{"name":"Asha","marks":[92,88],"active":true,"fee":1500.50}

Format with 2 spaces:

{
  "name": "Asha",
  "marks": [
    92,
    88
  ],
  "active": true,
  "fee": 1500.5
}

Two things changed besides the layout. A space was added after each colon, and 1500.50 became 1500.5, since both are the same number once parsed. Minify would return the input on one line with that same change to the fee.

Details That Can Change

  • Large integers: numbers beyond 9007199254740991 lose precision. An ID such as 12345678901234567890 comes out as 12345678901234567000. If your data has long numeric IDs, keep them as strings or check them after formatting.
  • Number style: trailing zeros and exponent notation are normalised, so 2.50 becomes 2.5 and 1e3 becomes 1000.
  • Duplicate keys: if an object contains the same key twice, only the last value survives, with no warning.
  • Key order: keys that look like whole numbers, such as "2" or "10", are moved to the front of their object in ascending order. Other keys keep their original order.
  • Escapes: Unicode escape sequences in strings may be written back as the actual characters, for example a Devanagari or accented letter instead of its backslash-u code.

Choosing Between Format and Minify

Use Format when a person needs to read or review the data: debugging an API response, checking a configuration file, or comparing two payloads line by line. Four-space indentation is easier to follow in deeply nested data; two spaces keeps wide structures on screen.

Use Minify when the JSON will be stored or sent by a program, for example in an environment variable, a URL parameter, a database field or a request body, where line breaks are unnecessary or can cause problems.

Converting JSON to XML and CSV

{{ 'json-formatter.guide.convertXml' | translate: 'To XML wraps your data in a single root element. Each object key becomes a tag, and each item of an array repeats its parent's tag, so "categories": ["Finance", "Health"] becomes two "categories" elements in a row. A top-level array becomes a list of item elements. Characters such as &, < and > are escaped, and keys that are not valid XML names, for example ones starting with a digit or containing spaces, have the bad characters replaced with an underscore.' }}

To CSV turns an array of objects into a table: each object is one row and every key that appears in any object becomes a column. Nested objects are flattened into dotted column names, so owner.country holds the value of country inside owner. Arrays inside a row are kept as JSON text in one cell. Cells containing commas, quotes or line breaks are quoted the standard way, and the downloaded file opens correctly in Excel, including the rupee symbol and Hindi text.

JSONXMLCSV
"name": "Asha"<name>Asha</name>Column "name"
"owner": { "city": "Pune" }<owner><city>Pune</city></owner>Column "owner.city"
"tags": ["a", "b"]<tags>a</tags><tags>b</tags>One cell: ["a","b"]
"note": null<note/>Empty cell

CSV can only show flat rows, so a single number or string cannot be converted, and deeply nested data is easier to read as XML or formatted JSON.

Frequently Asked Questions

It parses your JSON text and re-outputs it with consistent indentation (pretty-print) or as a single compact line (minify). It also checks that the JSON is valid, pointing to the line and column of any error, and can convert the data to XML or CSV.

Standard JSON does not allow any of them. Strings and keys must use double quotes, the last item in an object or array cannot be followed by a comma, and comments are not part of the format. Files such as tsconfig.json or VS Code settings accept these extras, but strict parsers, including this one, do not. Remove them and try again.

No, all parsing and formatting happens locally in your browser — your JSON data is never uploaded anywhere.

JavaScript stores numbers with about 15 to 17 significant digits, so integers larger than 9007199254740991 are rounded when parsed. The formatted output then shows the rounded value. Systems that use very large IDs often send them as strings for this reason.

Keys that are whole numbers, such as "1" or "2024", are always listed first and in ascending order when JavaScript writes out an object. The data is unchanged, since JSON objects have no required key order, but it can surprise you if you compare the output with the original text.

A CSV file is a table of rows, so it needs an array of objects, a single object or a list of values. A JSON document that is just one number or string, or an empty array, has no rows to write. In that case use Format or To XML instead.
5.0 out of 5 (1 rating)
Rate this calculator:

Related Calculators

Was this tool helpful?