FileKiln

JSON Formatter & Validator

Format, validate, and minify JSON in your browser. Precise error messages with position, nothing uploaded.

Ready when you arejson formatter
Runs on your computer. Nothing gets uploaded.

Your stuff stays yours. The conversion happens in this page's JavaScript. Nothing you paste here leaves your machine, and the tool keeps working with the network unplugged.

Paste JSON and get it pretty-printed with two-space indentation, or minified to a single line for embedding. Validation is the byproduct: anything that formats is valid JSON, and anything that is not fails with the browser engine's own error message, which names the offending position. The strictness is the point - trailing commas, single quotes, and comments are not JSON, and this tool will tell you so instead of silently accepting them.

How to use the JSON formatter

  1. Paste your JSON into the JSON in box. An API response, a log line, or a whole config file all work, as long as it is one JSON value.
  2. Click Format to get an indented version, two spaces per level, in the Formatted out box.
  3. Or click Minify to get the same data on a single line with every optional space removed.
  4. If the output stays empty and a message appears under the buttons, the input is not valid JSON. Use the position in the message to find the problem, fix it in the input box, and click the button again.
  5. Click Copy result to copy the output, or Clear to empty both boxes.

What valid JSON looks like

JSON is defined by RFC 8259, and its grammar is small. A document is exactly one value: an object, array, string, number, true, false, or null. A bare 42 or "hello" is valid on its own. The rules that trip people up most:

  • Object keys must be strings in double quotes. {a: 1} and {'a': 1} are JavaScript, not JSON.
  • Strings cannot contain a raw tab or line break. Write them as \t and \n.
  • Numbers cannot have leading zeros, a leading +, or a trailing decimal point, and NaN and Infinity do not exist.
  • Nothing is allowed after the value except whitespace, so two objects back to back are two documents, not one.

What formatting changes besides whitespace

The formatter parses your text into data and writes it back out, so the output is equivalent JSON but not always identical characters. Numbers are rewritten in their shortest form: 1.50 becomes 1.5 and 1E3 becomes 1000. Escapes that are not required are written as plain characters, so "café" becomes "café" and "\/path" becomes "/path". Empty objects and arrays print as {} and [] on one line. Key order is kept as written.

A worked example

Paste this single line:

{"order":1042,"paid":true,"items":[{"sku":"A-7","qty":2,"price":19.50}],"note":null,"ship":{}}

Click Format and you get:

{
  "order": 1042,
  "paid": true,
  "items": [
    {
      "sku": "A-7",
      "qty": 2,
      "price": 19.5
    }
  ],
  "note": null,
  "ship": {}
}

Click Minify on the same input and you get:

{"order":1042,"paid":true,"items":[{"sku":"A-7","qty":2,"price":19.5}],"note":null,"ship":{}}

In both outputs 19.50 became 19.5. The value is the same number, but if you are diffing files byte for byte, this is why a line changed.

Common problems and how to fix them

Error wording comes from your browser, so it varies. Recent Chrome and Edge versions give a character position plus a line and column; Firefox and Safari phrase things differently but still point at the first problem.

"Bad control character in string literal"

A string contains a real tab or line break, which often happens when JSON is assembled by hand or copied out of a terminal that wrapped a long line. Replace the break inside the quotes with \n, or the tab with \t.

"Unexpected non-whitespace character after JSON"

The parser finished one complete value and found more text. The usual causes are newline-delimited JSON (one object per line, common in log exports), a JSONP wrapper, or a stray comment after the closing brace. Format one line at a time, or wrap NDJSON lines in [ ] with commas between them.

A long ID changed its last digits

Numbers are parsed as 64-bit floats, so integers beyond 9,007,199,254,740,991 lose precision without any error. 9007199254740993 formats as 9007199254740992. Many APIs send large IDs as strings for this reason. If yours sends them as numbers, do not copy formatted output back into systems that need exact values.

A key disappeared

When one object contains the same key twice, only the last value is kept, with no warning. {"a":1,"a":2} formats as {"a": 2} spread over three lines. If a value is missing after formatting, search the original for a repeated key.

An error near the start, although the JSON looks right

Text copied from a word processor, chat app, or slide deck often has curly quotes (“ ”) instead of straight ones, and the parser stops at the first key. A file that begins with an invisible byte order mark fails the same way. Replace curly quotes with ", and if that is not it, delete and retype the first character.

Related tasks

Once your JSON is valid, you can turn it into a config file with the JSON to YAML converter or into a spreadsheet with the JSON to CSV converter. To see what changed between two formatted versions, use the text diff checker.

Questions this tool gets asked

Is this also a JSON validator?

Yes. Formatting only succeeds on valid JSON, so a successful format is a validation pass. Invalid input produces the JavaScript engine's error message, which includes the position of the first problem.

Why does my JSON with comments fail?

Comments are not part of the JSON standard. Files that allow them (like some config formats) are JSON5 or JSONC, which are different formats. Remove the comments and strict JSON parsers everywhere will accept the file.

Is my JSON uploaded anywhere?

No. Parsing and formatting run in this page's JavaScript. Disconnect from the internet after loading and the tool keeps working.

Related tools