If you’re just starting out in programming, or work in a nearby field (product, data, technical support) and keep running into the word “JSON” without ever stopping to understand what it actually means, this post is the starting point.
JSON, in practice
JSON stands for JavaScript Object Notation. Despite the name, it’s not exclusive to JavaScript: it’s a text format used by practically every programming language to represent data in an organized way. If you’ve ever opened a configuration file, seen an API response, or looked at an app’s data in the browser, you’ve probably already seen JSON without knowing that was its name.
A simple example:
// json
{
"name": "Ana",
"age": 30,
"active": true
}
This represents a person named Ana, 30 years old, who is active (in this context, “active” could mean anything, an active user in a system, for example).
Why JSON exists
Before JSON became popular, it was common to use XML to represent structured data in systems that exchange information with each other (for example, a website talking to a server). XML works, but it’s more verbose.
// xml
<person>
<name>Ana</name>
<age>30</age>
<active>true</active>
</person>
JSON emerged as a leaner alternative, easier to read and, most importantly, easier to convert directly into the data structures programming languages already use natively (objects, lists, etc.), without needing complex parsing libraries.
The building blocks of a JSON
A JSON is always made up of a combination of these basic elements.
Objects, delimited by curly braces {}, containing key-value pairs.
{"name": "Ana"}
Arrays, delimited by square brackets [], containing a list of values.
["apple", "banana", "orange"]
Strings, always in double quotes.
"any text"
Numbers, without quotes.
42
3.14
Booleans, true or false, without quotes.
true
Null, representing the absence of a value.
null
Combining the elements
In practice, a JSON almost always combines these elements in a nested way. An object can contain another object, or an array, and vice versa.
// json
{
"name": "Ana",
"hobbies": ["reading", "running"],
"address": {
"city": "New York",
"zip": "10001"
},
"phone": null
}
Here, hobbies is an array inside the object, address is another nested object, and phone uses null because that information wasn’t provided.
Where JSON is used day to day
- APIs: practically every modern API exchanges data in JSON format between client and server
- Configuration files: many tools use
.jsonfiles for configuration (likepackage.jsonin Node.js projects) - NoSQL databases: databases like MongoDB store documents in a format very close to JSON
- Data exchange between systems: when two different systems (sometimes written in different languages) need to exchange information
What isn’t valid in JSON
Worth flagging a few rules upfront that tend to confuse beginners, and that have their own posts with more detail on the blog:
- Keys and strings always in double quotes, never single
- No trailing comma allowed after the last item
- No support for comments
- No
undefinedorNaNvalues (those only exist in JavaScript, not in JSON)
Next steps
If you want to better understand any of these specific points, or you’re already writing JSON and want to confirm it’s correct, paste the content into JSON Validator. It flags syntax errors right away, including the exact position of the problem.