Smart Apps Pro

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

  1. Keys and strings use double quotes. Single quotes are not valid.
  2. Separate items with commas.
  3. No comma after the last item. This is the most common mistake.
  4. Every opening bracket needs a closing one.
  5. Keys are followed by a colon.
  6. 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

  1. Copy the file first.
  2. Change values, not structure, if you can.
  3. Watch the commas when you add or remove lines.
  4. Keep indentation neat, since it helps you see nesting.
  5. 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.

Get Notepad+ Text Editor →

Notepad+ Text Editor app icon

Notepad+ Text Editor

A fast, advanced text editor for notes and code, with emoji support

Get the app

More about Notepad+ Text Editor