A JSON file stores data in a format that both humans and programs can read
JSON stands for JavaScript Object Notation. It is a plain-text file format — meaning you can open it in any text editor — that holds structured data in a way that is easy for programs to parse and for people to understand at a glance. A JSON file uses curly braces, square brackets, and key-value pairs to organize information. The file extension is .json.
JSON was originally designed for JavaScript, but today nearly every programming language can read and write it. You will encounter JSON files when working with web applications, APIs, configuration settings, databases, and data storage. Unlike formats that require special software to open, a JSON file is readable in Notepad, TextEdit, or any code editor.
Key Takeaways
- JSON files are plain text that store data using curly braces, square brackets, and key-value pairs in a format both humans and programs can read.
- The basic building blocks are objects (enclosed in curly braces), arrays (enclosed in square brackets), strings (in quotes), numbers, booleans, and null values.
- JSON is language-independent, meaning Python, Java, C#, PHP, and other languages can all parse and generate JSON without special tools.
- Common uses include storing configuration settings, exchanging data between web servers and browsers, and organizing data in NoSQL databases like MongoDB.
How JSON structures data with objects and arrays
The core of JSON is the object, which is a collection of key-value pairs wrapped in curly braces. Each key is a string in quotes, followed by a colon, then the value. For example:
{"name": "Sarah", "age": 28, "city": "Portland"}
An array is an ordered list of values wrapped in square brackets. Arrays can hold objects, strings, numbers, or other arrays. For example:
["apple", "banana", "orange"]
You can nest objects inside arrays and arrays inside objects to create complex structures. A JSON file might describe a list of people, where each person is an object with properties like name, email, and phone number. The file remains readable because the indentation and structure make the hierarchy clear.
Data types that JSON supports
JSON recognizes six basic data types. Strings are text enclosed in double quotes. Numbers can be integers or decimals and do not need quotes. Booleans are true or false (lowercase, no quotes). Null represents the absence of a value. Objects are key-value pairs in curly braces. Arrays are ordered lists in square brackets.
This simplicity is intentional. JSON does not support every data type that a programming language might have — for instance, there is no native date type, so dates are usually stored as strings in a standard format like "2024-01-15". This constraint makes JSON predictable and easy to parse across different systems.
Why programs use JSON instead of other formats
JSON competes with other data formats like XML, CSV, and YAML. Compared to XML, JSON is more compact and faster to parse because it uses less syntax. A CSV file is simpler for flat, tabular data but cannot represent nested structures. YAML is more human-friendly to write by hand but requires more careful parsing.
JSON became the standard for web APIs because it is lightweight, language-independent, and fast to transmit over the internet. When you load a web page that pulls data from a server, that data often travels as JSON. Mobile apps, desktop software, and backend systems all use JSON to exchange information. It is also the default format for NoSQL databases like MongoDB, which store documents as JSON-like structures.
Opening and editing a JSON file
You can open a JSON file in any text editor: Notepad on Windows, TextEdit on Mac, or VS Code, Sublime Text, or Atom if you want syntax highlighting that color-codes the structure. Syntax highlighting makes it easier to spot missing commas or mismatched braces.
When you edit a JSON file, the structure must remain valid or programs will refuse to read it. Common mistakes include forgetting commas between key-value pairs, using single quotes instead of double quotes around strings, or leaving a trailing comma after the last item in an array. Many code editors will warn you about these errors in real time.
If you need to validate a JSON file before using it, you can paste it into an online JSON validator or use command-line tools. Most programming languages also have built-in functions to check whether a JSON string is valid before attempting to parse it.
Real-world examples of JSON in use
A weather application might receive JSON from a server that looks like this:
{"city": "Seattle", "temperature": 52, "condition": "rainy", "humidity": 85}
A social media platform stores user profiles as JSON objects with nested arrays for posts and comments. A configuration file for a web server might be JSON that specifies which ports to listen on, which files to serve, and which security rules to enforce. An e-commerce site uses JSON to send product information from the database to your browser, where JavaScript reads it and displays the product details on the page.
APIs — the interfaces that let different software talk to each other — almost always return JSON. If you request weather data, stock prices, or location information from a public API, the response will be formatted as JSON.
The difference between JSON and JavaScript objects
JSON and JavaScript objects look similar but are not the same. A JavaScript object is a data structure that exists in memory while a program runs. JSON is a text format for storing or transmitting that data. When JavaScript code reads a JSON file or receives JSON from a server, it converts the JSON text into a JavaScript object that the program can work with.
The syntax is nearly identical, but JavaScript objects can contain functions and other features that JSON cannot represent. JSON is the portable, standardized format; JavaScript objects are the working version inside a JavaScript program.
Frequently Asked Questions
Can I open a JSON file in Excel or Google Sheets?
Excel and Google Sheets can import JSON, but they work best with flat, tabular data. If your JSON has nested objects or arrays, the spreadsheet will flatten it or display it awkwardly. For complex JSON, a text editor or code editor is clearer.
What happens if my JSON file has a syntax error?
Programs will reject it and usually report an error message pointing to the line with the problem. Common issues are missing commas, mismatched braces, or quotes around keys. A code editor with syntax highlighting will catch most of these before you try to use the file.
Is JSON secure for storing passwords or sensitive data?
JSON is plain text, so it offers no built-in encryption. Never store passwords, API keys, or personal information in a JSON file without additional protection. If you must store sensitive data, encrypt the file or use a dedicated secrets management tool.
Can I convert JSON to other formats like CSV or XML?
Yes. Many online converters and programming libraries can transform JSON into CSV, XML, YAML, or other formats. The conversion works best when the data structure maps cleanly to the target format — for instance, a flat array of objects converts easily to CSV, but deeply nested JSON may lose structure in the conversion.
Do I need to learn JSON to use web applications?
No. Most users never see JSON directly. Developers and programmers work with it, but web browsers and apps handle JSON behind the scenes. You only need to understand JSON if you are writing code, building APIs, or configuring software that uses JSON files.