What a JSON file is and why you edit it

A JSON file is a text file that stores data in a format computers can read and understand. JSON stands for JavaScript Object Notation. It uses curly braces, square brackets, and quotation marks to organize information into pairs — a label and a value. For example, a JSON file might say "name": "James" or "age": 30.

You edit JSON files when you need to change settings, update configuration data, or modify information that a program reads. A website might store user preferences in JSON. A mobile app might use JSON to hold default settings. A server might read a JSON file to know how to behave. Unlike a Word document, a JSON file has strict rules about format — if you break those rules, the program that reads it will fail.

The good news: you do not need special software. Any text editor works. The hard part is following JSON's formatting rules exactly, because even a missing comma or misplaced quotation mark will break it.

Key Takeaways

  • JSON files are plain text and can be opened in any text editor like Notepad, VS Code, or Sublime Text.
  • JSON requires exact formatting: strings must be in double quotes, numbers and true/false values must not be, and commas must separate all items except the last one in a list.
  • The most common mistakes are forgetting commas between items, using single quotes instead of double quotes, and leaving a trailing comma after the last item.
  • Many text editors can highlight JSON syntax and show you errors before you save, which catches mistakes faster than waiting for the program to fail.

Opening a JSON file in a text editor

Right-click the JSON file on your computer. Select Open with and choose a text editor. On Windows, Notepad is built in. On Mac, use TextEdit (but switch to plain text mode first under Format menu). On any system, VS Code (free from Microsoft) or Sublime Text are better choices because they highlight JSON syntax and catch errors.

If you double-click a JSON file and it opens in your browser or a program you did not intend, right-click again, choose Open with, and pick your text editor by name. Do not use Microsoft Word or Google Docs — they add invisible formatting that breaks JSON.

Understanding JSON structure and formatting rules

JSON has three basic building blocks: objects (wrapped in curly braces {}), arrays (wrapped in square brackets []), and values (text, numbers, true, false, or null). A key-value pair looks like this: "color": "blue". The key is always in double quotes. The value can be text (in double quotes), a number (no quotes), or true/false (no quotes).

Here is a real example:

{   "name": "James",   "age": 30,   "active": true,   "hobbies": ["reading", "coding", "hiking"] }

Notice: each key is in double quotes, text values are in double quotes, numbers and true are not, and there is a comma after every item except the last one. The last item (hobbies) has no comma after it. This is the most common mistake — adding a comma after the last item breaks the file.

Making changes without breaking the format

Before you edit, read through the entire file to understand its structure. Identify where your change goes. If you are changing a value (the part after the colon), keep the same type: if it was a number, use a number; if it was text, use text in double quotes.

If you are adding a new key-value pair, add a comma after the previous item first, then add your new pair on a new line. If you are deleting an item, remove the comma that comes before it (not after). If the item you are deleting is the last one in a list, remove the comma from the item above it instead.

After you make changes, save the file. If your editor supports JSON validation (VS Code does), it will show a red squiggle under errors. Fix those before you close. If you are unsure, paste your JSON into a free JSON validator online — search "JSON validator" — and it will tell you exactly where the problem is.

Common mistakes and how to fix them

The most frequent error is a missing or misplaced comma. Every item in an object or array needs a comma after it, except the last one. If you add a new line and forget the comma on the line above, the file breaks. Check the line before your change first.

The second mistake is using single quotes instead of double quotes. JSON requires double quotes around all keys and text values. Single quotes look similar but are not valid. If you copy text from a website or email, check that the quotes are straight double quotes, not curly ones (which some programs auto-correct to).

The third mistake is a trailing comma — a comma after the last item in an object or array. This is valid in some programming languages but not in JSON. If your file has {"name": "James",}, remove that final comma.

The fourth mistake is forgetting to quote text values. If you write "age": thirty instead of "age": "thirty", it breaks (unless thirty is a number, then it should be "age": 30 with no quotes).

Using a text editor with built-in JSON tools

VS Code is free and shows JSON errors as you type. read it from code.visualstudio.com. Open your JSON file, and if there is a formatting problem, you will see a red squiggle and an error message in the Problems panel at the bottom. Hover over the error to see what is wrong.

Sublime Text (free to use, optional paid license) also highlights JSON syntax. Open the file, then go to View menu and select Syntax, then JSON. It will color-code your file so strings, numbers, and keys are visually different, making errors easier to spot.

Both editors can also auto-format your JSON to make it readable. In VS Code, right-click in the file and select Format Document. This fixes indentation and spacing, though it will not fix logical errors like missing commas or wrong quote types.

Testing your edited JSON file

After you save, the program that reads this file will tell you if something is wrong. If it fails to load or gives an error message, go back to your text editor and check the error message carefully — it usually points to the line number where the problem starts.

If you are not sure the file is valid before you hand it to a program, use a free online JSON validator. Search "JSON validator" and paste your entire file into the tool. It will show you exactly which line has the problem and what kind of error it is. This is faster than guessing.

Keep a backup of the original file before you edit, so you can compare if something goes wrong. Many text editors have an undo history, but a backup file is safer.

Frequently Asked Questions

Can I edit a JSON file in Notepad?

Yes, Notepad works because JSON is plain text. However, Notepad does not highlight syntax or show errors, so you are more likely to miss mistakes. A free editor like VS Code is better because it catches errors as you type.

What does the error "unexpected token" mean?

This usually means a comma is missing, a quote is wrong, or a bracket is mismatched. Look at the line number the error points to and the line before it. Check for missing commas, single quotes instead of double quotes, or an extra comma after the last item.

Can I add comments to a JSON file?

No, JSON does not support comments. If you need to explain something, you have to add it as a key-value pair, like "note": "this is a comment". Some programs extend JSON to allow comments, but standard JSON does not.

What if I accidentally saved over the original file and made it invalid?

If your text editor has an undo feature, use it. If not, check your computer's file history or backup. Windows has File History; Mac has Time Machine. If neither is available, the file may be unrecoverable, which is why keeping a backup before you edit is important.

Do I need to know programming to edit JSON?

No. You only need to understand the format: keys in double quotes, text values in double quotes, numbers and true/false without quotes, and commas between items. If you follow those rules, you can edit JSON without writing any code.