Skip to content
beginthings.

Dev & Data

JSON formatter & validator

Paste JSON to check and format it. If something is wrong, you get the exact line and column. A repair mode fixes comments, trailing commas, single quotes and similar common mistakes.

Your JSON

Options

Layout

Result

Format, check and fix JSON in one place

Paste JSON from an API response, a config file or a log line and the tool does three jobs. It checks the text against the strict JSON rules and, if something is wrong, points to the exact line and column of the first problem. It reformats valid JSON with 2 spaces, 4 spaces or tabs, or minifies it to a single line. And it reports the top-level type (object, array or single value), the number of keys, the nesting depth and the size in bytes before and after.

Three options change the output. "Sort keys A to Z" puts object properties in alphabetical order, which makes two versions of a file easier to compare. "Escape non-ASCII characters (\uXXXX)" turns characters such as é or the Hindi word नाम into escape codes for systems that only accept plain ASCII. "Repair common mistakes" switches to a forgiving parser, covered below.

Reading the error messages

Most "invalid JSON" errors come from a handful of rules: property names must be in double quotes, strings use double quotes, there are no comments, numbers cannot have leading zeros, and the last item in an object or array cannot be followed by a comma. The validator names the rule that failed. Some examples, all produced by the tool:

  • {"name":"Asha","age":31,} gives "Line 1, column 24: There is a trailing comma before the closing bracket."
  • {"id": 007} gives "Line 1, column 8: Invalid number.", because JSON does not allow leading zeros.
  • A missing comma between two lines gives "Expected a comma or a closing bracket here." at the start of the line after the gap, which is where the parser noticed.

When the position points at the start of a line, look at the end of the line above it first.

What repair mode can and cannot fix

With "Repair common mistakes" ticked, the parser accepts comments, trailing commas, single-quoted strings, unquoted property names and Python or JavaScript values such as True, False, None, undefined and NaN. It then writes clean standard JSON and lists every kind of change it made, so you can review the result before using it.

For example, {name: 'Asha', active: True, // note followed by tags: ['a','b',]} comes out as a valid object with "name", "active": true and a "tags" array. The note reads "Repaired: unquoted keys, single quotes, Python/JavaScript literals, comments, trailing commas." Repair mode cannot guess at missing brackets or text that is not JSON-like at all, and it turns undefined, NaN and Infinity into null, so check those fields.

Big numbers and duplicate keys

Many online formatters run your text through the browser's own JSON.parse, which quietly rounds integers longer than about 16 digits. This tool uses its own parser and copies numbers digit for digit, so an ID like 12345678901234567890 comes out unchanged. It also spots duplicate keys. Given {"b":1,"a":2,"b":3} it keeps both entries in the output and warns "Duplicate keys found: b. Most parsers keep only the last value." To compare two versions of a file line by line, the text diff checker works well on formatted output.

Frequently asked questions

Why does it say a number is invalid?

Strict JSON does not allow leading zeros such as 007, so the error points at that number. A plus sign (+1.5) or a trailing decimal point (2.) is not allowed either. Tick "Repair common mistakes" and those two are rewritten as 1.5 and 2.

Does formatting change my data?

No. Only whitespace changes, plus key order if you tick sort and escape codes if you tick the non-ASCII option. Values and numbers stay exactly as written.

How do I minify JSON?

Choose "Minify". The result removes every space and line break outside strings, and the size rows show how many bytes you saved.

Can I save the result as a file?

Yes. "Download" saves the output as formatted.json, created on your device.

Privacy

Your inputs are processed by your browser and are not sent to BeginThings. API keys, tokens and customer records in your JSON stay on your device.

More free tools you might need