What a JSON file actually is
A JSON file is a text file that stores information in a format computers can read and organize. JSON stands for JavaScript Object Notation. The file itself is just plain text — you can open it in any text editor like Notepad (Windows), TextEdit (Mac), or gedit (Linux) — but the information inside is arranged in a specific pattern so that programs know how to find what they need.
JSON files end with the .json extension, like contacts.json or settings.json. They are commonly used to store configuration settings, contact lists, financial records, or data exported from websites and apps. When you read your data from Google, Facebook, or your bank, it often comes as a JSON file.
The structure uses curly braces {} to hold groups of information and square brackets [] to hold lists. Each piece of information has a label (called a "key") and a value. For example: "name": "Sarah" means the key is "name" and the value is "Sarah".
Key Takeaways
- JSON files are plain text files you can open in any text editor, but they follow a specific format that programs use to organize information.
- The structure uses curly braces for objects and square brackets for lists, with each piece of data labeled with a key and a value.
- You can read a JSON file by opening it in a text editor, but formatting tools and online viewers make large or complex files much easier to understand.
- Common problems like missing commas or mismatched brackets will prevent the file from working, but error messages usually point you to the exact line with the problem.
- If you need to edit a JSON file, keep the structure intact: every key needs quotes, every value needs the right format, and commas separate items (but not the last one).
Opening a JSON file in a text editor
The simplest way to read a JSON file is to open it in a text editor. Right-click the file, select "Open with," and choose Notepad (Windows), TextEdit (Mac), or any text editor you have. The file will display as plain text, and you can read the contents directly.
For small files with just a few lines, this works fine. For larger files with hundreds or thousands of lines, the text will be hard to scan because it is usually all crammed together without line breaks. The information is still there, but finding a specific piece of data becomes tedious.
If you open a JSON file and see an error message instead of text — something like "This file type is not supported" — the file may be corrupted or your system does not recognize the .json extension. Try renaming the file to end in .txt instead, or try a different text editor.
Using a formatter to make JSON readable
A JSON formatter is a tool that takes a JSON file and displays it in a clean, organized way with proper indentation and line breaks. This makes it much easier to see the structure and find the information you need.
You have two options: online formatters and desktop applications. Online formatters like JSONLint (jsonlint.com) or JSON Formatter (jsonformatter.org) let you paste the contents of your JSON file into a box, and they display it formatted and color-coded. This is free and requires no installation. The downside is that you are sending your file contents to a website, so if the file contains sensitive information like passwords or financial data, this is not safe.
For sensitive files, use a desktop process instead. Visual Studio Code (free, from microsoft.com) is a text editor that recognizes JSON files automatically and formats them as you type. When you open a .json file in VS Code, it indents the structure, color-codes the different parts, and even highlights errors. Other options include Sublime Text and Notepad++, both free or low-cost.
Understanding the structure: keys, values, and nesting
JSON organizes information using a consistent pattern. A key is the label for a piece of data, and a value is the actual data. Keys are always in quotes. Values can be text (in quotes), numbers (no quotes), true or false, or another group of data.
Here is a straightforward example:
{"name": "Sarah", "age": 28, "active": true}
This file has three pieces of information: a name (text), an age (number), and an active status (true or false). Each key-value pair is separated by a comma.
Nesting means putting one group of data inside another. For example, if you want to store a person's name and their address, you might nest the address information inside the person's data:
{"name": "Sarah", "address": {"street": "123 Main St", "city": "Portland", "state": "OR"}}
Here, "address" is a key whose value is another group of data (enclosed in curly braces). This lets you organize related information together. Square brackets [] create a list. If you have multiple people, you might write:
[{"name": "Sarah", "age": 28}, {"name": "James", "age": 35}]
This is a list of two people, each with their own name and age.
Finding specific information in a JSON file
Once you understand the structure, finding information is straightforward. Look for the key you want, and the value right after the colon is the answer. If you are looking for someone's email address, search for the word "email" in the file. The value next to it is the address.
In a formatted file, use your text editor's search function (Ctrl+F on Windows, Cmd+F on Mac) to jump to the key you need. This is much faster than reading through hundreds of lines by hand.
If the file is very large or you need to extract multiple pieces of information, consider opening it in a spreadsheet process like Excel or Google Sheets. Many spreadsheet programs can import JSON files and display them as tables, which makes it easier to sort, filter, and analyze the data. The exact steps depend on your spreadsheet program, but usually you go to File > Open and select the JSON file.
Common errors and what they mean
JSON files are strict about format. A single missing comma or mismatched bracket will break the file. When you try to open a broken JSON file in a formatter or program, you will usually get an error message that tells you exactly where the problem is.
Common errors include:
- Missing comma: "Expected ',' at line 5" means you forgot a comma between two key-value pairs. Add a comma after the value on line 5.
- Mismatched brackets: "Unexpected token '}' at line 12" usually means you have too many closing brackets or braces. Count the opening and closing brackets to find the mismatch.
- Unquoted key: "Unexpected token at line 8" often means a key is missing quotes. Keys must always be in quotes, like "name", not name.
- Text value without quotes: If a value is text, it must be in quotes. "status": "active" is correct; "status": active is not.
If you see an error, go to the line number mentioned and look for these issues. Most of the time, the problem is within a few lines of where the error is reported.
Editing a JSON file safely
If you need to change information in a JSON file, open it in a text editor and make your changes carefully. The structure must stay intact, or the file will break.
Follow these rules: every key must be in quotes, every text value must be in quotes, numbers and true/false do not need quotes, and separate each key-value pair with a comma (except the last one in a group). If you add a new key-value pair, put a comma after the previous one and before the new one.
After you make changes, save the file and open it in a formatter or your program to check for errors. If the formatter shows an error, fix it before saving again. This prevents you from accidentally breaking the file.
If you are not sure about the format, make a copy of the file first and edit the copy. That way, if something goes wrong, you still have the original.
Frequently Asked Questions
Can I open a JSON file in Excel?
Yes. In Excel, go to File > Open and select the JSON file. Excel will import it and display it as a table. This works best for straightforward JSON files with a clear list structure. Complex nested files may not import cleanly, and you may need to rearrange columns afterward.
What is the difference between JSON and CSV?
CSV (comma-separated values) is a simpler format used mainly for tables and spreadsheets. JSON is more flexible and can store nested groups of data, making it better for complex information. JSON is also what most websites and apps use to send data to each other.
Is it safe to open a JSON file from the internet?
Opening a JSON file to read it is safe. The file is just text. However, if a program tries to run or execute a JSON file, it could potentially do something harmful. Only open JSON files from sources you trust, and never run a JSON file as a program or script unless you know what it does.
Why does my JSON file look like one long line?
The file is not formatted with line breaks. This is normal — JSON does not require line breaks, and many programs create JSON files as a single long line to save space. Use a formatter to add indentation and line breaks so you can read it. The file will work the same way either way.
Can I convert a JSON file to another format?
Yes. You can convert JSON to CSV, Excel, or other formats using online converters or desktop tools. Search for "JSON to CSV converter" or "JSON to Excel converter" to find options. Keep in mind that some information may be lost if the new format does not support nested data the way JSON does.