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
Drafting Emails in a Text Editor First
Why drafting important emails in a separate text editor prevents accidental sends, improves clarity and helps you write calmer messages.
Read article →Keeping a CV in Plain Text for Easy Updates
Maintain a master CV in a plain-text file so you can update it anywhere, tailor it quickly and paste it cleanly into online application forms.
Read article →Keeping a Work Diary for Performance Reviews
Record your achievements, feedback and challenges throughout the year in a simple text file, so performance reviews and promotions are easier to prepare.
Read article →Outlining a Novel in a Text Editor
Use a plain-text outline to plan characters, chapters and plot for a novel — flexible, searchable and easy to rearrange.
Read article →