If you've ever worked with web APIs, configuration files, or data storage, you've almost certainly encountered JSON. It stands for JavaScript Object Notation, but don't let the name fool you – JSON is used by virtually every programming language, not just JavaScript.
In this tutorial, you'll learn:
- What JSON is and why it's so popular
- The basic syntax (objects, arrays, key-value pairs)
- Real-world examples (API responses, config files)
- How to validate and format JSON online (with our free tool)
What Exactly is JSON?
JSON is a lightweight data-interchange format. It's designed to be easy for humans to read and write, and easy for machines to parse and generate. Because of this balance, JSON has become the standard format for sending data between a server and a web application (REST APIs).
Before JSON, XML was widely used, but XML is more verbose and harder to parse. Example comparison:
<!-- XML version -->
<person>
<name>John Doe</name>
<age>30</age>
</person>
// JSON version
{
"name": "John Doe",
"age": 30
}
JSON is much cleaner and takes less bandwidth. That's why almost every public API – Twitter, Google Maps, GitHub – uses JSON.
JSON Syntax Rules (Simplified)
JSON is built on two universal structures:
- Object: an unordered collection of key/value pairs (enclosed in curly braces
{ }). - Array: an ordered list of values (enclosed in square brackets
[ ]).
Inside an object, each key must be a string (in double quotes), followed by a colon : and the value. Pairs are separated by commas.
Valid value types in JSON:
- String (in double quotes) –
"hello" - Number –
123or3.14 - Boolean –
trueorfalse - Null –
null - Object –
{ ... } - Array –
[ ... ]
Important: JSON does not support comments, functions, or undefined values. Keep it simple.
Real-World JSON Examples
1. API Response (GitHub user)
{
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://avatars.githubusercontent.com/u/1",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
}
2. Configuration file (VS Code settings snippet)
{
"editor.fontSize": 14,
"editor.fontFamily": "Fira Code",
"editor.lineHeight": 22,
"files.autoSave": "onFocusChange",
"workbench.colorTheme": "One Dark Pro"
}
How to Validate and Format JSON
When you're writing or debugging JSON, the smallest mistake (like a trailing comma) will break the entire file. That's why you need a JSON formatter and validator.
We've built a free online JSON tool that:
- Validates your JSON syntax and points to errors
- Formats (pretty-prints) minified JSON with indentation
- Minifies JSON to save bandwidth
- Works entirely in your browser – no data is uploaded to any server