How to format JSON
JSON is made of names and values inside { } (objects) and [ ] (lists, called arrays). Spaces, tabs and line breaks between those parts mean nothing to a computer, so a formatter can add them for people: each item goes on its own line, one indent step deeper for every bracket it sits inside. Minifying takes them all out again to make the file smaller.
Here it is with your numbers:
- Checked all 196 characters against the JSON grammar (RFC 8259): no errors.
- Put each name and value on its own line, indented 2 spaces for each level, with a colon and a space after each name.
- Copied every number and piece of text exactly as typed, so the data is unchanged.
It means your JSON is valid and now 19 lines long.
The example is the sample from the JSON standard itself. This formatter copies every number and piece of text exactly as you typed it, so 12345678901234567890 stays as it is; tools that read JSON into JavaScript numbers can change numbers that long.
Source RFC 8259 · The JSON Data Interchange Format, §2 JSON Grammar ↗RFC 8259 · §6 Numbers ↗
What is JavaScript Object Notation (JSON)?
JSON is a way of writing data as text that almost every programming language can read. A JSON value is one of six things:
| Kind | Looks like |
|---|---|
| Object (names and values) | {"name": "Ann", "age": 34} |
| Array (a list) | [116, 943, 234] |
| String (text) | "View from 15th Floor" |
| Number | 800, -2.5, 1e6 |
| True or false | true, false |
| Nothing | null |
Names in an object should be unique: programs disagree on what a repeated name means (many keep only the last), so this page points them out.
Source RFC 8259 · §3 Values ↗RFC 8259 · §4 Objects ↗
Common JSON errors and how to fix them
| Mistake | Not valid | Valid |
|---|---|---|
| Comma after the last item | [1, 2, 3,] | [1, 2, 3] |
| Single quotes | {'name': 'Ann'} | {"name": "Ann"} |
| Name without quotes | {name: "Ann"} | {"name": "Ann"} |
| A comment | {"a": 1} // note | {"a": 1} |
| Capital True or None | [True, None] | [true, null] |
| Leading zero | {"zip": 02134} | {"zip": "02134"} |
Text in quotes also can’t hold a real line break or tab: write \n and \t instead. JavaScript accepts some of these mistakes; JSON doesn’t, and the first one found stops the check.
Source RFC 8259 · §7 Strings ↗
FAQs
What is a JSON file format?
A JSON file is plain text holding JSON data, usually with the .json extension (the official media type is application/json). Shared JSON must be written in UTF-8.
Source RFC 8259 · §11 IANA Considerations (media type and .json) ↗
How do I open a JSON file?
It is plain text, so any text editor opens it (Notepad, TextEdit, VS Code). To read it easily, copy the text into the box above and it is laid out with one item per line.
How do you make a JSON file readable?
Format it: put each name and value on its own line and indent each level. Spaces and line breaks between the parts don’t change the data, so formatting is always safe.
Source RFC 8259 · The JSON Data Interchange Format, §2 JSON Grammar ↗
How do I format JSON correctly?
Put names and text in double quotes, separate items with commas (none after the last), write true, false and null in lowercase, and leave out comments. Numbers have no leading zeros.
Source RFC 8259 · §3 Values ↗
How do I validate JSON?
Check it against the JSON grammar. Paste it above: the first error is shown with its line and column and a fix, and valid JSON is marked “Valid JSON”.
Source RFC 8259 · §9 Parsers ↗
Sources
- RFC 8259: The JSON Data Interchange Format, §2 JSON Grammar
- RFC 8259: §3 Values
- RFC 8259: §4 Objects
- RFC 8259: §6 Numbers
- RFC 8259: §7 Strings
- RFC 8259: §8.1 Character Encoding
- RFC 8259: §9 Parsers
- RFC 8259: §11 IANA Considerations (media type and .json)