What is JSON?
JSON (JavaScript Object Notation) is a lightweight text format for storing and exchanging data. It is the standard way web APIs send data to apps and websites, and it is also used for configuration files, databases and logs. It is easy for people to read and easy for programs to parse.
A JSON document is built from just two structures: objects (a set of named values inside curly braces) and arrays (an ordered list of values inside square brackets). Here is a small example:
{
"name": "Wabten",
"free": true,
"tools": ["json", "password"],
"owner": { "name": "A. Example", "email": null }
}
JSON syntax rules
- Data is written as name and value pairs, separated by a colon:
"name": "value". - Names (keys) must be in double quotes. Single quotes are not allowed.
- Values can be a string, a number, true, false, null, an object or an array.
- Items in an object or array are separated by commas, with no comma after the last item.
- Strings use double quotes. Line breaks and tabs inside a string must be written as
\nand\t. - Comments,
undefined,NaNandInfinityare not part of standard JSON.
Format, validate or minify: which should you use?
- Format (beautify) adds indentation and line breaks so humans can read the data. Use it when you are debugging an API response or reading a config file.
- Validate checks that the text is correct JSON and tells you exactly where the first problem is. Use it before sending data to an API or saving a config file.
- Minify removes every unnecessary space and line break to make the data as small as possible. Use it to reduce the size of data you send or store.
- Sort keys puts the keys of every object in alphabetical order, which makes two documents easier to compare.
Common JSON errors and how to fix them
Most invalid JSON comes from a handful of mistakes. This table shows what each looks like and how to fix it. The formatter points to the exact line and column, and Repair can fix many of them for you.
| Problem | Example | How to fix it |
|---|---|---|
| Trailing comma | {"a": 1,} | Remove the comma after the last item |
| Single quotes | {'a': 1} | Use double quotes around keys and strings |
| Unquoted key | {a: 1} | Wrap the key in double quotes: {"a": 1} |
| Comment | {"a": 1} // note | Remove the comment (JSON does not support them) |
| Missing comma | {"a": 1 "b": 2} | Add a comma between the two items |
| Missing bracket or brace | {"a": [1, 2} | Add the missing closing ] or } |
| Invalid value | {"a": undefined} | Use null instead of undefined, NaN or Infinity |
| Raw line break in a string | a string split over two lines | Write the line break as \n |
Fix broken JSON with Repair
Repair reads JSON the way a forgiving human would and writes it back as strictly valid JSON. It can remove comments, delete trailing commas, convert single quotes to double quotes, add missing quotes around keys, escape raw line breaks inside strings, and replace Python-style True, False and None, as well as undefined, NaN and Infinity, with valid JSON values. After a repair, the tool lists exactly what it changed so you can check it.
Repair cannot guess missing data. If a bracket, brace or quote is missing, or two values have no separator, you will still see an error with its location so you can fix it by hand.
Why exact numbers matter
Many tools read JSON with JavaScript’s built-in parser, which stores every number as a 64-bit floating point value. That silently changes any whole number above 9,007,199,254,740,991 and can alter decimals. The number 12345678901234567890 becomes 12345678901234567000, which corrupts IDs, order numbers and timestamps.
This formatter does not convert numbers at all. It keeps each number exactly as you wrote it, including 1.0, 1E+5 and very large integers, so formatting and minifying never change your data.
Working with JSON in code
Every major language can read and write JSON. In JavaScript, JSON.parse() turns text into a value and JSON.stringify() turns a value back into text. The third argument of stringify sets the indentation:
const data = JSON.parse(text);
const pretty = JSON.stringify(data, null, 2); // 2-space indent
const compact = JSON.stringify(data); // minified
In Python, use the built-in json module: json.loads(text) to read and json.dumps(data, indent=2) to write. In PHP, use json_decode() and json_encode() with the JSON_PRETTY_PRINT flag.
Is it safe to paste my JSON here?
Yes. All parsing, formatting and repairing happen in your browser. Your JSON is not uploaded, logged or stored, and the tool keeps working if you switch off your connection after the page has loaded. Even so, avoid pasting live passwords, API keys or private tokens into any website.