JSON-based file
JSON (which stands for JavaScript Object Notation) is one of the most popular formats for storing and exchanging data on the internet today.
Think of it as the universal language of data: it’s lightweight, completely text-based, and easy for both humans to read and computers to parse.
Here is a complete breakdown of what JSON files are, how they work, and why they are everywhere.
What is JSON Used For?
Whenever you use an app or browse a website, data is constantly moving between a server and your device. JSON is the container that carries that data.
- Web APIs: When an app fetches weather data, movie listings, or user profiles from a server, that data is almost always delivered as JSON.
- Configuration Files: Many modern software tools and text editors (like VS Code) use
.jsonfiles to store user settings.
- NoSQL Databases: Databases like MongoDB store data in a format that is heavily based on JSON.
📝 The Anatomy of a JSON File
JSON is built on two universal structures:
- key/value pairs (similar to a dictionary or object)
- and lists (arrays).
Here is what a standard .json file looks like:
JSON
{
"name": "Alex Mercer",
"age": 28,
"isEmployee": true,
"skills": ["JavaScript", "Python", "SQL"],
"address": {
"city": "San Francisco",
"state": "CA"
},
"certifications": null
}
JSON Data Types
As seen in the example above, JSON supports a specific set of data types:
- String: Text wrapped in double quotes (
"Alex Mercer") - Number: Integers or floating-point numbers (
28,3.14) - Boolean:
trueorfalse - Array: An ordered list of values wrapped in square brackets (
["JavaScript", "Python"]) - Object: A nested collection of key/value pairs wrapped in curly braces (
{"city": "San Francisco"}) - Null: An empty value (
null)
⚠️ Strict Rules of JSON
Because computers rely on JSON to be perfectly predictable, it has very strict syntax rules. A single misplaced comma will break a JSON file.
- Double Quotes Only: All keys and string values must use double quotes (
"key"). Single quotes ('key') are invalid. - No Commas at the End: The last item in an object or array must not have a trailing comma.
- No Comments: JSON does not allow comments
(like// this is a comment). It is strictly for data.
⚖️ JSON vs. XML
| Feature | JSON | XML |
|---|---|---|
| Readability | High, clean structure | Moderate, cluttered with tags |
| File Size | Lightweight (smaller file sizes) | Heavier due to opening/closing tags |
| Parsing Speed | Fast (native to JavaScript) | Slower, requires complex parsing |
| Data Types | Supports numbers, booleans, arrays | Everything is treated as text |
Before JSON took over, XML (Extensible Markup Language) was the king of data exchange. Today, JSON is generally preferred for web development.
Example of the difference:
XML
<user>
<name>Alex</name>
<age>28</age>
</user>
JSON
// JSON Version
{"name": "Alex", "age": 28}
🛠️ How to Open and Work with JSON
Because JSON files are just plain text, you can open them with absolutely any text editor (Notepad, TextEdit, VS Code).
If you are writing or editing JSON and want to make sure you didn't miss a comma or quote, you can paste your code into a free online tool like JSONLint to validate it.
Are you looking to use JSON for a specific project, or are you just curious about how data works behind the scenes?