JSON Formatting and Validation for Beginners
JSON formatting turns a long, hard-to-read line of data into neatly indented text, and validation checks that the text follows JSON’s strict rules. The quickest way to do both is to paste your data into ToolOrca’s free JSON Formatter and press Format: valid JSON is indented instantly, and if something is wrong you see the exact line and column of the error. Everything runs in your browser, so nothing you paste is uploaded.
This beginner’s guide explains what JSON is, the handful of syntax rules that cause almost every error, and how to read, repair and convert JSON.
What JSON is
JSON (JavaScript Object Notation) is a plain-text format for structured data. APIs send it, apps save settings in it, and databases export it. It is built from just a few pieces:
- Objects in curly braces:
{ "key": value } - Arrays in square brackets:
[ value, value ] - Strings in double quotes:
"Phnom Penh" - Numbers:
42,3.14,-7 - Booleans:
trueorfalse - null: an empty value
Here is a small, valid example:
{
"name": "Sokha",
"age": 28,
"languages": ["Khmer", "English"],
"address": { "city": "Siem Reap", "zip": null },
"active": true
}
How to format and validate JSON step by step
- Paste your JSON into the JSON Formatter. You can also drop a .json file on the box or press Open file. With Format on paste ticked, pasted JSON is formatted automatically.
- Choose the indent. Under Indent, pick 2 spaces, 4 spaces or Tab, and tick Sort keys A→Z if you want keys in alphabetical order.
- Press Format (or Minify). Format (Ctrl/⌘ + Enter) makes the JSON readable; Minify removes all optional whitespace.
- Fix any error. If the JSON is invalid, read the line and column in the red message, or press Repair JSON to fix common problems automatically.
- Explore and copy. Open the Tree tab to fold nested data and copy paths, check the Stats tab for depth, key count and size, then press Copy or Download .json.
Tip: Press Sample to load example JSON if you just want to try the tool and see how the tree view works.
The syntax rules behind most JSON errors
JSON looks like JavaScript, but it is much stricter. These are the mistakes beginners make most often.
Trailing commas. No comma is allowed after the last item:
{ "a": 1, "b": 2, }
Remove the comma after 2.
Single quotes. Keys and strings must use double quotes:
{ 'name': 'Dara' }
Correct form: { "name": "Dara" }.
Unquoted keys. JavaScript accepts { name: "Dara" }, but JSON needs { "name": "Dara" }.
Comments. JSON has no comments at all, so // note or /* note */ makes it invalid.
Python values. True, False and None are Python, not JSON. JSON uses true, false and null.
Special numbers. NaN, Infinity and undefined are not valid JSON values. Use null or a real number.
Unescaped characters. A line break, tab or double quote inside a string must be written as \n, \t or \". A raw line break inside quotes is a common reason a copied log line will not parse.
What Repair JSON fixes
Config files, JavaScript objects and Python dictionaries often look like JSON but are not. Repair JSON reads them leniently and writes strict JSON. It removes comments and trailing commas, changes single quotes to double quotes, quotes unquoted keys, turns Python True, False and None into true, false and null, replaces NaN, Infinity and undefined with null, and adds commas that are missing between two values.
For example, this input:
{ name: 'Dara', active: True, tags: ['a', 'b',], // test
}
becomes valid JSON:
{
"name": "Dara",
"active": true,
"tags": [
"a",
"b"
]
}
The message lists every kind of change made, so you can check the result. If the input is too broken to guess, such as a missing closing bracket in the middle, the validator still shows the exact position of the problem.
Pretty vs minified JSON
Pretty (formatted) JSON adds line breaks and indentation so people can read and compare it. Minified JSON removes every optional space; the data is identical, but the file is smaller, which is what you want in production APIs and config bundles. The Stats tab shows both the pretty and minified size.
Tree view, paths and big numbers
Large API responses are much easier to read in the Tree tab. You can fold and unfold objects with Expand all and Collapse all, and search keys and values. Click any key or value and its path appears, with Copy path and Copy value buttons. Choose the notation you need:
- JSONPath:
$.reviews[0].user(testing tools and Postman) - JavaScript:
data.reviews[0].user(code) - jq:
.reviews[0].user(command line) - JSON Pointer:
/reviews/0/user(JSON Patch and OpenAPI)
Big numbers need care. JavaScript stores numbers as 64-bit floats, so JSON.parse silently rounds integers above 9,007,199,254,740,991. An ID like 9007199254740993123 comes back changed in many tools. The JSON Formatter keeps such numbers exactly as written and tells you how many it found, a hint that your own code may need to read them as strings or BigInt.
Converting JSON to CSV, YAML and back
- JSON to CSV turns an array of objects into a spreadsheet file. Every key becomes a column, nested objects are flattened into names like
address.city, and you can pick a comma, semicolon, tab or pipe delimiter before you press Download .csv. - CSV to JSON goes the other way, turning a spreadsheet export into a JSON array.
- JSON to YAML writes the same data as YAML for Kubernetes, Docker Compose or CI files, and its YAML → JSON direction reads YAML back as JSON.
To see live JSON from an API, the REST API Client sends a request from your browser and shows the response body pretty-printed, and its Format JSON button tidies and checks a request body before you send it.
Common mistakes to avoid
- Copying JSON from a chat app or document. Some apps change straight quotes
"into curly quotes, which JSON does not accept. Paste from a plain-text source when you can. - Assuming JavaScript rules apply. Trailing commas, single quotes and comments are fine in JavaScript but break JSON.
- Ignoring duplicate keys. JSON allows the same key twice in one object, but most parsers keep only the last value. The formatter warns you, because it usually signals a bug.
- Losing long IDs. If a tool or your code rounds big numbers, IDs and amounts can silently change. Store them as strings.
- Pasting secrets into tools that upload data. Use tools that run in your browser for responses that contain tokens or personal data.
Summary
JSON is simple once you know its strict rules: double quotes everywhere, no trailing commas, no comments, and only true, false and null as special values. Paste your data into the JSON Formatter to format and validate it, use Repair JSON for near-JSON from code or config files, explore large data in the tree view, and convert it to CSV or YAML when another tool needs a different format.
Frequently asked questions
How do I check if my JSON is valid?
Paste it into the JSON Formatter and press Format. Valid JSON is indented and confirmed; invalid JSON shows a red message with the line and column of the first problem, and the cursor jumps there.
Why is a trailing comma an error in JSON?
The JSON standard does not allow a comma after the last item of an array or object, so [1, 2, 3,] is invalid even though JavaScript accepts it. Delete the last comma, or press Repair JSON to remove it for you.
Can JSON have comments?
No. Standard JSON has no comments. Files such as JSONC or JSON5 allow them, but a strict parser will reject them. Repair JSON removes //, /* */ and # comments and gives you standard JSON.
What is the difference between pretty and minified JSON?
They contain exactly the same data. Pretty (formatted) JSON adds line breaks and indentation so people can read it. Minified JSON removes every optional space so the file is smaller, which suits production APIs and config bundles.
Is it safe to paste API responses with tokens into the formatter?
The JSON Formatter parses your data in your browser and does not upload it, so tokens and personal data stay on your device.
How do I convert JSON to a spreadsheet?
Use JSON to CSV. Paste a JSON array of objects, choose a delimiter, check the preview and press Download .csv. The file opens in Excel or Google Sheets, and nested objects become columns such as address.city.