JSON Basics: The Punctuation That Breaks Files
A beginner's guide to reading and editing JSON files, the rules for commas, quotes and brackets, and the mistakes that cause errors.
JSON is a popular format for storing data, used by websites, apps and settings files. It's plain text, so you can read and edit it in any editor, but it is picky about punctuation.
What JSON looks like
{
"name": "Ana",
"age": 34,
"active": true,
"languages": ["English", "Portuguese"],
"address": {
"city": "Lisbon"
}
}
The building blocks
| Piece | Written as | Example |
|---|---|---|
| Object | curly braces | { ... } |
| Array (list) | square brackets | [ ... ] |
| Key | text in double quotes | "name" |
| String | text in double quotes | "Ana" |
| Number | digits, no quotes | 34 |
| Boolean | true or false, no quotes | true |
| Null | the word null | null |
The rules
- Keys and strings use double quotes. Single quotes are not valid.
- Separate items with commas.
- No comma after the last item. This is the most common mistake.
- Every opening bracket needs a closing one.
- Keys are followed by a colon.
- JSON has no comments.
Common errors
| Mistake | Example |
|---|---|
| Trailing comma | "age": 34, before a closing brace |
| Missing comma | between two items |
| Single quotes | 'name' instead of "name" |
| Unquoted key | name: "Ana" |
| Missing bracket | an unclosed { or [ |
| Comments | // note inside the file |
Editing safely
- Copy the file first.
- Change values, not structure, if you can.
- Watch the commas when you add or remove lines.
- Keep indentation neat, since it helps you see nesting.
- Use a validator if you're unsure, before using the file.
Special characters in strings
Some characters must be escaped with a backslash: a double quote is ", a backslash is \, and a new line is \n.
Uses
- App settings.
- Data from websites and APIs.
- Configuration for tools.
A calm approach
If a JSON file stops working after an edit, the problem is almost always a missing or extra comma or bracket. Compare with your backup and look at the line just before the error.
Reading JSON
Even without editing, learning to read JSON helps you understand the data your apps use.
Notepad+ Text Editor
A fast, advanced text editor for notes and code, with emoji support
More about Notepad+ Text Editor
Editing Config Files on Your Phone: Doing It Carefully
What configuration files are, the common formats, and sensible precautions before making a quick edit.
Read article →Editing README Files and Project Notes
What a README is, what belongs in one, and how to keep project notes tidy in plain text.
Read article →Quick HTML Edits: Fixing a Web Page from Your Phone
How HTML is structured and how to make small, safe changes to a page in a text editor, such as fixing a typo or a link.
Read article →Tabs or Spaces? Indentation in Plain Text and Code
Why indentation matters, the difference between tabs and spaces, and how to avoid mixed-indentation problems when editing files.
Read article →