Tools / JSON formatter
JSON Formatter and Validator
Format messy JSON so it’s readable, check that it’s valid, and find the exact line and column of any error.
Free, no sign-up. Everything runs in your browser, so your data is never uploaded.
How to use it
- Paste JSON into the box or open a
.jsonfile. - Click Format to indent it, or Minify to remove all whitespace, which makes it smaller for sending over a network.
- If the JSON is invalid, the message shows the line and column of the problem and the cursor jumps there.
Common JSON errors
Most invalid JSON comes from a handful of mistakes, often because it was written by hand or copied from JavaScript or Python:
- Single quotes. JSON strings must use double quotes:
"name", not'name'. - Trailing commas.
[1, 2, 3,]is valid in JavaScript and Python but not in JSON. - Unquoted keys.
{name: "Ana"}must be{"name": "Ana"}. - Python values.
True,FalseandNonemust betrue,falseandnull. - NaN and Infinity. They aren’t allowed in JSON. Pandas writes missing values as
nullfor this reason. - Comments. JSON has no comments. Remove
//and/* */lines.
When the validator finds one of these, it tells you which one it is likely to be.
Format JSON in Python
import json
with open("data.json") as f:
data = json.load(f) # raises an error with line and column if invalid
print(json.dumps(data, indent=2, sort_keys=True))From the command line, python -m json.tool data.json does the same. To load JSON into a table, see the CSV to JSON converter or pd.json_normalize in our guide to collecting data from APIs.
FAQ
Is my JSON sent to a server?
No. Formatting and validation use your browser’s built-in JSON parser. Nothing leaves your computer, so it’s safe for API keys, tokens and private data.
Does formatting change my data?
Only the whitespace, unless you choose Sort keys, which reorders keys alphabetically. Values stay the same. One exception: whole numbers with more than 15 significant digits, such as some database IDs, can lose precision in any JavaScript-based tool. Keep those as strings.
What’s the difference between formatting and validating?
Validating only checks that the JSON is correct and reports its structure. Formatting checks it too, then rewrites it with consistent indentation.
Related
- CSV to JSON converter
- Unix timestamp converter: for date fields in API responses
- How to use APIs to collect data
