What is JSON? A Beginner's Guide with Examples
JSON (JavaScript Object Notation) is a lightweight, text-based format for storing and exchanging data. It represents information as key–value pairs and ordered lists, is easy for both humans to read and machines to parse, and has become the standard format for web APIs, configuration files, and data storage across nearly every programming language.
What is JSON?
JSON is a way to write structured data as plain text. Because it is just text, it can be sent over a network, saved to a file, or logged to a console, and then reconstructed into usable data on the other side. It was originally derived from JavaScript, but today it is completely language-independent — Python, Java, C#, Go, Ruby, PHP, and virtually every other language can read and write it.
The format became popular because it hits a rare sweet spot: it is compact enough for machines to parse quickly, yet readable enough for a human to understand at a glance. That balance is why JSON replaced heavier formats like XML for most web communication.
Why is JSON so popular?
- It is human-readable. You can open a JSON file and understand the data without special tools.
- It is language-independent. Every major language has a built-in or standard JSON parser.
- It maps naturally to data structures. Objects become dictionaries/maps and arrays become lists.
- It is compact. Less verbose than XML, which means smaller payloads and faster transfers.
- It is the API standard. REST and most modern web APIs speak JSON by default.
JSON syntax: the building blocks
JSON is built from just two structures — objects and arrays — and a small set of value types.
- Object — an unordered set of key–value pairs wrapped in curly braces
{ }. Keys must be double-quoted strings. - Array — an ordered list of values wrapped in square brackets
[ ]. - String — text wrapped in double quotes, e.g.
"hello". - Number — an integer or decimal, e.g.
42or3.14. - Boolean —
trueorfalse. - null — represents an empty or unknown value.
That is the entire type system. There are no dates, no functions, and no undefined — a deliberate simplicity that keeps JSON portable.
A real JSON example
{
"name": "Ada Lovelace",
"born": 1815,
"isMathematician": true,
"fields": ["mathematics", "computing"],
"employer": null
}
Here the object has five keys. The value of fields is an array of strings, born is a number, isMathematician is a boolean, and employer is null. Every key is a double-quoted string, and pairs are separated by commas — the two rules people most often get wrong.
JSON vs XML vs YAML
JSON is not the only data format. Here is how it compares to the two other formats you will meet most often:
| Feature | JSON | XML | YAML |
|---|---|---|---|
| Readability | High | Medium | Very high |
| Verbosity | Low | High | Low |
| Comments | No | Yes | Yes |
| Data types | 6 built-in | Text only | Rich |
| Best for | APIs, data exchange | Documents, legacy systems | Config files |
For sending data between a server and a browser, JSON almost always wins. For human-edited configuration, many teams prefer YAML because it allows comments. You can move between them instantly with a JSON to YAML converter.
Common JSON mistakes
Most JSON errors come from a handful of easy-to-miss rules:
- Trailing commas — a comma after the last item (
[1, 2, 3,]) is invalid in JSON. - Single quotes — strings and keys must use double quotes, not single quotes.
- Unquoted keys —
{ name: "Ada" }is valid JavaScript but invalid JSON; the key must be"name". - Comments —
//and/* */are not allowed in standard JSON. - Missing brackets or commas — a single missing
}breaks the whole document.
When a parser rejects your JSON, a JSON validator will point to the exact character where parsing failed so you can fix it fast.
Where is JSON used?
Once you start looking, JSON is everywhere in modern software:
- Web APIs — REST and most modern APIs send and receive JSON.
- Configuration files —
package.json,tsconfig.json, and countless tools store settings as JSON. - NoSQL databases — document stores like MongoDB keep records as JSON-like documents.
- Tokens — the payload of a JWT is Base64-encoded JSON.
- Structured logs — many logging systems emit one JSON object per line for easy searching.
How to read JSON in code
Every major language ships with a JSON parser, so turning a JSON string into usable data is a one-liner. In JavaScript:
const data = JSON.parse('{"name": "Ada"}');
console.log(data.name); // "Ada"
const text = JSON.stringify(data); // back to a string
And in Python it is just as short:
import json
data = json.loads('{"name": "Ada"}')
print(data["name"]) # Ada
The golden rule: always use the built-in parser. Never run JSON through eval, which would execute it as code and open a security hole.
JSON best practices
- Use consistent key naming. Pick camelCase or snake_case and apply it everywhere.
- Validate untrusted input. Check incoming JSON against a schema before you rely on it.
- Keep it reasonably flat. Deeply nested structures are harder to read and consume.
- Prefer ISO 8601 for dates. JSON has no date type, so store dates as standard strings.
How to work with JSON online
You do not need to install anything to work with JSON. These free, browser-based tools run entirely on your device, so even private data stays with you:
- JSON Formatter — beautify and indent messy or minified JSON.
- JSON Validator — check for syntax errors with exact positions.
- JSON to CSV — turn a JSON array into a spreadsheet-ready CSV.
Conclusion
JSON is the connective tissue of the modern web: a simple, readable, language-independent format for moving data around. Learn its six value types and its handful of syntax rules, and you can read almost any API response or config file with confidence. When you hit a formatting or validation snag, reach for a browser-based JSON tool and keep moving.
Try the tools
Frequently Asked Questions
What does JSON stand for?
JSON stands for JavaScript Object Notation. It was derived from JavaScript's object syntax, but it is now a language-independent format that virtually every programming language can read and write.
Is JSON a programming language?
No. JSON is a data format, not a programming language. It only describes data — it cannot contain logic, functions, or executable code. That limitation is exactly what makes it safe and portable.
Can JSON have comments?
No. The JSON specification does not allow comments. If you need comments in a config file, use a superset like JSON5 or JSONC, or switch to YAML, which supports comments natively.
What is the difference between JSON and a JavaScript object?
A JavaScript object is code that lives in memory; JSON is a text string. JSON also has stricter rules: keys must be double-quoted strings, and values are limited to six types with no functions, dates, or undefined.
Is JSON secure?
JSON itself is just data and cannot execute, so it is safe to transmit. Risks come from how you parse it — always use a standard JSON parser rather than evaluating JSON as code, and validate untrusted input.
CodeUtilityKit Team builds free, privacy-first developer tools that run entirely in your browser. Every guide is written and reviewed by developers who use these tools daily.