JSON Formatter and Viewer

Paste JSON, then format it, minify it, fix it or browse it as a tree. It runs in your browser and nothing is uploaded.

JSON formatter

Values kept exactly: big numbers, decimals and duplicate keys are not rewritten. See the proof.

2 objects1 array8 keys9 values2 levels deep

Quick answer. Paste your JSON and press Format to indent it or Minify to compact it, or switch to Tree to view it as expandable nodes. If it is invalid, the error shows the line and column; press Fix to repair the common mistakes. Unlike a formatter built on JSON.parse, this one does not round large numbers: {"id": 1234567890123456789, "price": 10.50, "rate": 1E2} stays exactly as written, where JavaScript would turn the id into 1234567890123456800.

Updated . The rules cited are from RFC 8259, the Python documentation and MDN, listed at the bottom.

What counts as valid JSON

This validator checks syntax against the JSON standard, RFC 8259. The rules that trip people up most:1

  • Keys and strings use double quotes. An object member name is a string, so it must be in double quotes. {a: 1} and {'a': 1} are JavaScript, not JSON.
  • No comments and no trailing commas. The grammar has no place for either, so [1, 2,] is invalid even though JavaScript allows it.
  • true, false and null are lowercase. True, False and None are Python spellings.
  • Numbers are plain. No leading zeros (07), no leading plus sign, and no NaN or Infinity.
  • Any value can be the whole document. Since RFC 8259, 42, "text" and null are each a valid JSON text, not only objects and arrays.

Syntax is all this checks. It does not check that the data has the fields you expect; that is a schema check, which is a different tool. For a verdict on its own, with the size of the document and a warning for anything another program may read differently, use the JSON validator.

Common JSON errors, and how to fix them

These are the mistakes that produce most "invalid JSON" messages. The table is generated by this page's own validator: the third column is where it stops, the fourth is the hint it gives, and the last says whether the Fix button repairs it.

Ten mistakes, where this validator stops on each, and whether the Fix button repairs it
MistakeThe JSONWhere it stopsWhat it meansFix button
Trailing comma{"a": 1, "b": 2,}line 1, column 17Trailing comma: JSON does not allow a comma before a closing bracket or brace. Remove the comma before this character.Yes: {"a": 1, "b": 2}
Single quotes{'a': 1}line 1, column 2Strings and keys must use straight double quotes, not single quotes.Yes: {"a": 1}
Unquoted key{a: 1}line 1, column 2Object keys must be in double quotes.Yes: {"a": 1}
Comment{"a": 1 // note\n}line 1, column 9JSON does not allow comments.Yes: {"a": 1 \n}
Python values{"ok": True, "v": None}line 1, column 8The words true, false and null must be lowercase in JSON. (True is a Python spelling.)Yes: {"ok": true, "v": null}
Missing comma{"a": 1 "b": 2}line 1, column 9Two items are not separated by a comma.No, fix by hand
Leading zero[07]line 1, column 3Numbers cannot have leading zeros. Write 7, not 07.No, fix by hand
Unclosed bracket{"a": [1, 2line 1, column 12The text ends before the JSON is complete. A bracket, brace or quote is probably not closed.No, fix by hand
NaN{"n": NaN}line 1, column 7NaN is not a JSON value. Use null or a string instead.No, fix by hand
Raw line break in a string{"a": "line one\nline two"}line 1, column 16A raw line break or tab inside a string is not allowed. Write \n or \t instead.No, fix by hand

The Fix button changes only what it recognises: it copies every double-quoted string exactly, and on text that is already valid it changes nothing. It cannot guess what you meant by a missing comma or an unclosed bracket, so those it leaves for you, with the location and hint.

Beautify, minify and sort keys

Beautifying (formatting, pretty-printing) adds indentation and line breaks so nested data is easy to read; pick 2 spaces, 4 spaces or a tab. For more control over the layout, with 3 or 8 spaces, short arrays kept on one line and escapes shown as characters, use the JSON beautifier. Minifying removes every character that is not needed, giving the smallest text for the same data, which is useful before sending or storing it. The sample above, minified:

{"id":4417,"name":"HatchLoop Tools","tags":["json","formatter","validator"],"price":10.50,"active":true,"owner":{"name":"Ada","email":null}}

Sort keys puts every object's keys in order, which makes two documents easy to compare. Keys are ordered by their UTF-16 code units, and equal keys keep their original order. An unsorted document with nested objects and an array (arrays are never reordered), sorted:

{
  "a": {
    "y": 2,
    "z": 1
  },
  "b": 2,
  "c": [
    3,
    1
  ]
}

JSON viewer: browse JSON as a tree

Switch the result from Text to Tree to use this page as a JSON viewer. Every object and array becomes a node you can open and close, with its size beside it: {3} for an object with three keys, [12] for an array of twelve items. The top two levels are open when the tree appears. Scalars are shown exactly as written, so a string keeps its quotes and a number keeps its trailing zero, and keys keep the order they have in the text. It is the quickest way to find one value in a response you have never seen.

Very large documents are cut off at 4,000 nodes in the tree so the page stays responsive; the text view has no such limit.

Why this formatter does not change your numbers

The usual way to build a JSON formatter is to parse the text and print it again, and in JavaScript that quietly rewrites data: every number becomes a 64-bit floating-point value. Take {"id": 1234567890123456789, "price": 10.50, "rate": 1E2}. Parsed by JavaScript, the id becomes 1234567890123456800 (a different number), 10.50 becomes 10.5 and 1E2 becomes 100. A formatter that does this returns output that looks perfect and is wrong.

RFC 8259 says that good interoperability can be achieved by implementations that expect no more precision or range than IEEE 754 double precision provides, which means integers beyond 253 − 1 (9,007,199,254,740,991) may not survive a round trip through some software.1 Ids of that size are common in API responses, so this tool leaves every number, string escape and literal exactly as written, changes only the whitespace, and warns you when a document contains a number that other software may round. It also keeps duplicate keys: the RFC says names within an object should be unique, and that many parsers keep only the last one.1 Both are kept here and flagged, so you see what is really in the file.

How to format JSON in Python and JavaScript

In Python, json.dumps takes indent for pretty-printing and sort_keys=True to order the keys; from the command line, python -m json.tool file.json pretty-prints a file.2

import json data = json.loads(text) print(json.dumps(data, indent=2, sort_keys=True))

In JavaScript, the third argument of JSON.stringify sets the indentation: a number of spaces (clamped to 10) or a string of up to 10 characters.3

const pretty = JSON.stringify(JSON.parse(text), null, 2);

Both routes parse and re-print, so they have the number behaviour described above: a very large integer in JavaScript, or a value such as 10.50 in either language, is not guaranteed to come back as written. When the exact text matters, format it with a tool that preserves it, like this one.

Frequently asked questions

What is a JSON formatter?

A JSON formatter takes JSON text and rewrites it so people can read it: indented, one value to a line, with the nesting visible. This one also minifies, checks the syntax, fixes common mistakes and shows the data as a collapsible tree. It changes only whitespace, so the data stays exactly as written.

How do I format a JSON file?

Press Open a file and choose the .json file, or paste its text, then press Format and pick 2 spaces, 4 spaces or a tab. A file of up to 20 MB is read by your browser and never uploaded. Copy the result or download it. In a terminal, python -m json.tool file.json does the same with Python.

How can I beautify JSON?

Press Format: beautifying and formatting are the same thing. For more control over how the result looks, with sorted keys, short arrays kept on one line and escapes shown as characters, use the JSON beautifier.

How do I convert JSON into a readable format?

Paste it and press Format to indent it, or switch to the Tree view to open and close each object and array. If the text is full of unicode escapes, the JSON beautifier can show them as the characters they stand for.

How do I format JSON?

Paste it into the box and press Format. Pick 2 spaces, 4 spaces or a tab from the indent menu. The result appears next to the box, or under it on a narrow screen, with a count of objects, arrays, keys and values, and you can copy it or download it as a file.

How do I check whether my JSON is valid?

Press Validate, or just paste: the page checks as you type. Valid JSON is confirmed; invalid JSON gets the line and column where parsing stops, the line itself with a caret under the problem, and a hint such as "Trailing comma".

What is the difference between a JSON formatter, validator and beautifier?

They overlap. A validator checks that the text is valid JSON. A formatter or beautifier re-lays it out with indentation and line breaks. Formatting needs the text to be valid first, so every formatter validates, and this one does all three, plus minifying.

How do I fix invalid JSON?

Read the line and column and the hint, and fix that spot. For the usual mistakes, press "Fix common mistakes": it removes comments and trailing commas, changes single or curly quotes to double quotes, puts unquoted keys in quotes, and changes True, False and None to true, false and null. Missing commas and unclosed brackets you fix by hand.

Can JSON have comments?

No. The JSON grammar has no comments. Formats such as JSONC and JSON5 add them, but they are different formats: a strict JSON parser rejects them. The Fix button removes comments so the text becomes valid JSON.

Are trailing commas allowed in JSON?

No. A comma before a closing bracket or brace, as in [1, 2, 3,], is invalid. JavaScript allows it in its own array and object literals, which is why it appears so often in pasted code.

Does formatting change my data?

Not here. Only whitespace changes: numbers, string escapes, key order and duplicate keys are kept exactly as written. Formatters built on JSON.parse can round large integers (for example {"id": 1234567890123456789, "price": 10.50, "rate": 1E2}, where the id becomes 1234567890123456800), drop trailing zeros and remove duplicate keys.

What does "Sort keys" do?

It puts each object's keys in order (by UTF-16 code unit) at every level, leaves arrays in their original order, and keeps duplicate keys in their original relative order. It is useful for comparing two documents.

Can I open a JSON file, or load JSON from a URL?

You can open a file from your device (up to 20 MB); it is read by your browser and never uploaded. Loading from a URL is not offered: many APIs refuse requests made from another website, and it would mean this page making a network request for you. Download the file and open it instead.

What happens to a byte-order mark at the start of a file?

The standard says JSON should not have one, and that a parser may ignore it. This page drops it when it opens a file, and the Fix button removes one you pasted.

Is my JSON sent to a server?

No. Formatting, validating, fixing and loading a file all happen in your browser, and nothing you paste or open is transmitted. We count page visits and button clicks with our own analytics on our own server, and those events carry none of your data.

What is a JSON viewer, and what is the tree view for?

A JSON viewer shows JSON as a structure you can explore instead of as text. The tree view does that: it shows the result as collapsible nodes, each object and array with its size, so you can explore a large document without scrolling through every line. Values are shown exactly as written.

Sources

  1. Bray, T. (ed.), RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format (IETF, 2017): a JSON text is a serialized value; the literal names must be lowercase; numbers have no leading zeros and cannot be Infinity or NaN; names within an object should be unique; interoperability of numbers beyond IEEE 754 binary64; encoding and byte-order marks.
  2. Python Software Foundation, json — JSON encoder and decoder: the indent and sort_keys parameters of json.dumps, and the command-line pretty printer (python -m json, with python -m json.tool as the older name).
  3. MDN Web Docs, JSON.stringify(): the space argument, a number clamped to 10 or a string truncated to 10 characters.

The formatter is checked against JavaScript's own printer on hundreds of random documents, and its validity decisions against Python's json module on thousands of valid and mutated documents.