JSON

JSON Editor, Formatter & Compare

Paste JSON into A or B to check it as you type; an error shows its line and column, such as "Line 3, column 9: Trailing comma", and Repair fixes it. Switch to Tree or Table to edit values, and press Compare to see each added, removed and changed key between A and B.

Runs in your browser. Nothing you enter is sent to a server.

A
Open
Your browser fetches it directly; the server must allow it (CORS).
Copy
Copy
Transform
Differences
B
Open
Your browser fetches it directly; the server must allow it (CORS).
Copy

Transform A into B

Pick an array, then filter, sort and choose fields. The result goes into the other document; this one is not changed.

Filter
Sort
Pick fields (none ticked: keep whole items)
Steps
Preview

      
Advertisements

Two documents side by side

The editor has two documents, A and B. Each one can be shown three ways:

  • Text: the JSON itself, with line numbers and colours. Tab indents, Enter keeps the indent, and the line with an error is marked red.
  • Tree: collapsible nodes with item counts. Double-click a value or key to change it, or select a row and use Edit, Rename, Insert, Duplicate and Remove. Ctrl+click an arrow opens or closes everything inside it.
  • Table: an array of objects as rows and columns, for example a list of users. Click a header to sort the view; double-click a cell to edit it.

The buttons between the documents copy one into the other, transform one into the other, swap them, and turn Compare on. Drag the dotted line between them to give one more room, or use Full screen. On a phone the A and B tabs switch between them.

How does the editor check JSON?

It reads the text character by character against the JSON standard (RFC 8259) and stops at the first thing that is not allowed. The status bar names the problem and the line and column where it is, counted from 1. Common ones:

InputMessage
[1, 2,]Trailing comma: remove the comma before "]"
{'a': 1}Keys must use double quotes, not single quotes
{a: 1}Object keys must be in double quotes
{"a": 1 "b": 2}Missing comma between properties
{"ok": True}Unexpected "True": write it in lowercase, true
{"n": 012}Numbers cannot have leading zeros

Repair fixes all of these at once and lists what it changed. It also removes comments and ```json fences, unwraps ObjectId("…") and JSONP callbacks, wraps several values in a row (NDJSON) in an array, and completes JSON that was cut off.

Valid JSON can still hide two problems, so the editor warns about them with their line and column:

  • Duplicate keys. {"id": 1, "id": 2} is accepted by most parsers, but they keep only the last value.
  • Integers beyond Number.MAX_SAFE_INTEGER (9,007,199,254,740,991). JSON.parse in JavaScript reads 12345678901234567890 as 12345678901234567000.

Formatting

  • Format (Ctrl+I) puts one key or item per line, indented with 2 spaces, 4 spaces or a tab.
  • Compact (Ctrl+Shift+I) removes all whitespace between values, for the smallest size.
  • Sort keys orders the keys of every object by character code, which makes two versions easier to compare by eye.
  • Copy copies the document formatted, compact, or as one JSON string with escaped quotes, ready to paste inside code.

Numbers and duplicate keys are written out exactly as they were in the input. Every change can be undone with Ctrl+Z.

Transform: filter, sort and pick fields

Transform takes an array from one document and puts the result in the other. Choose the array, then any of:

  • Filter by a field: equals, does not equal, greater or less than, contains, exists. For example age > 30.
  • Sort by a field, ascending or descending. Text is sorted ignoring case, with numbers in natural order (item 2 before item 10).
  • Pick fields to keep only some keys of each item. Picking one field gives a plain list of its values.

The steps are shown as one line, such as users | filter age > 30 | sort name | pick id, name, with a preview of the result before you apply it.

How does Compare work?

Both documents are parsed, then walked together by key path. Differences are marked in both documents and listed below them. Each one is one of four kinds:

KindExample
Addedteam: only in B
Removedroles[1]: only in A
Changedaddress.city: "Bandung" → "Jakarta"
Type changedaddress.postcode: string "40115" → number 40115

Objects are matched by key, so the same keys in a different order count as identical. Arrays are compared by index. Numbers are compared by value: 1.0 equals 1, and long integers are compared digit by digit. Click a path in the list to show it in both documents.

Opening, saving and keeping your documents

  • Open a file from your computer, drop one onto a document, or load a URL (the server has to allow it).
  • Save (Ctrl+S) downloads the document as a .json file named after the document.
  • Both documents are kept in this browser's local storage, so they are still there next time. They are never sent to our server. Untick "Keep both documents in this browser" to remove them.

Limitations

  • Arrays are compared by position, not aligned by content. An item inserted at the start shows every later position as changed.
  • Comments, trailing commas and single quotes (JSON5, JSONC) are errors until you press Repair.
  • Nesting deeper than 1,000 levels is rejected.
  • Documents over about 300 KB are shown without colours so typing stays fast, and documents over 2 MB are not kept in the browser. The tree and table show long lists 100 and 200 rows at a time.

Questions

How do I find the error in invalid JSON?

The status bar under the document shows the first error with its line and column, for example "Line 3, column 9: Trailing comma: remove the comma before }", and the line is marked in red. "Go to error" puts the cursor there. "Repair" fixes the usual causes for you and lists what it changed.

What does Repair fix?

Comments, trailing commas, missing commas and colons, single quotes, curly quotes, unquoted keys, Python values (True, False, None), numbers such as +1 or .5, ``` code fences, JSONP and Mongo shell wrappers such as ObjectId("…"), several values in a row (NDJSON, wrapped in an array) and JSON that was cut off before it ended. Undo (Ctrl+Z) takes the repair back.

Does formatting change my numbers?

No. Numbers are written exactly as you typed them, so 12345678901234567890 stays 12345678901234567890. The editor warns you when a number is beyond Number.MAX_SAFE_INTEGER, because JSON.parse in JavaScript would round it.

How are two JSON documents compared?

Objects are compared key by key, so key order and whitespace do not matter. Arrays are compared by index: item 0 with item 0, item 1 with item 1. Differences are marked in both documents, and listed below them with their key path, such as address.city, and the old and new value.

Is my JSON uploaded anywhere?

No. Everything runs in your browser. If "Keep both documents in this browser" is ticked, the two documents are saved in this browser's local storage so they are still there next time; untick it to remove them. Opening a URL fetches it straight from your browser.

What happens with duplicate keys?

The editor keeps both entries in the text and warns you, with the line and column of the second one. Most parsers, including JSON.parse, keep only the last value; the tree, table and compare do the same.

Support this site

The tools are free and need no account. If one saved you time, a small donation helps keep them running.

Want a tool or feature? Suggest it for free, or donate and write your request in the message. Supporters' requests are looked at first.