JSON Editor FreeOpen the JSON editor

Docs/Format, compact, repair

JSON formatter and JSON repair

The JSON formatter lays JSON out on lines with the indentation you choose. Compact removes every space. Repair turns almost-JSON into valid JSON.

Updated

Open this page in the editor

Tidy a document

  1. Find the icon buttons Format, Indentation, Compact and Repair in the toolbar at the top of the panel you want to tidy. Point at one, or move to it with the keyboard, to see its name.
  2. Under Indentation, pick 2 spaces, 4 spaces or Tab. Picking one also formats the panel with it.
  3. Choose Format (Ctrl+I) or Compact (Ctrl+Alt+I). Both need valid JSON.
  4. If the JSON is broken, choose Repair (Ctrl+Alt+R). Undo puts back the original if you don’t like the result.

Keys

FormatCtrl+I
CompactCtrl+Alt+I
RepairCtrl+Alt+R
UndoCtrl+Z
Every shortcut

Format JSON: an example

To format JSON, paste it into a panel, or open a file, and press Format. JSON Editor Free works as a JSON formatter and beautifier: it puts each key and item on its own line and indents every level, so a one-line API response becomes easy to read.

For example, the one-line JSON {"name":"Ada","born":1815,"tags":["math","code"]} formatted with 2 spaces becomes 8 lines: { on the first line; "name": "Ada",, "born": 1815, and "tags": [ indented by 2 spaces; "math", and "code" indented by 4; then ] and } on lines of their own.

Compact does the reverse and turns it back into the single line, which is smaller to send or store. Both need valid JSON, so if the text is broken, press Repair first; see below.

Repair JSON: an example

To repair JSON, paste the broken text into a panel and press Repair. JSON Editor Free works as a JSON repair tool: it fixes the quotes, commas, brackets and values that stop text from being valid JSON, then checks the result with the same parser the editor uses.

For example, the Python-style text {'name': 'Ada', 'active': True, 'tags': ['math', 'code',] has single quotes, a Python True, a trailing comma and no closing brace. Repair turns it into {"name": "Ada", "active": true, "tags": ["math", "code"]}, which you can then format or compact.

Format and compact

Formatting keeps every number and string exactly as written; only the spaces and line breaks change. A formatted document ends with a line break, a compact one does not.

The indentation you choose is remembered and is also used when tree mode shows a document as text.

Formatting runs in your browser, so the JSON you format is not sent to a server.

Format, validate or repair?

  • Format and Compact need valid JSON. In text mode, invalid JSON is underlined and the status bar shows the line, the column and what is wrong, so you can fix it by hand; see Text, tree and table.
  • Repair is for text that is almost JSON: a JavaScript object with unquoted keys, a Python dict, JSON with comments or an API response that was cut off. Repair it first, then format it.
  • To check that the data has the right keys and types, not only valid syntax, use a JSON Schema; see JSON Schema.
  • To put keys in order before you format, see Sort. To see what a repair or an edit changed, compare the two versions side by side; see Compare two documents.

What Repair fixes

  • Single quotes, missing quotes around keys, and curly “smart” quotes.
  • Trailing commas, missing commas, and missing closing brackets or braces, including a document cut off part way.
  • // and /* */ comments, and Markdown code fences around the JSON.
  • Python None, True and False; MongoDB values such as NumberLong("1") and ISODate("…").
  • A JSONP wrapper like callback({...}), strings joined with +, and ... placeholders.
  • JSON that was stringified and escaped, and newline-delimited JSON, which becomes an array.

After a repair

The repaired text replaces the document as one undo step, and a toast offers Undo. Repair on JSON that is already valid changes nothing and says so.

If Repair can’t find a valid reading, it leaves the text alone and shows where it stopped.

PreviousEditing in tree modeNextCompare documents