If you've ever built a website, called an API, or peeked inside a package.json file, you've already met JSON. It stands for JavaScript Object Notation, and it's basically the universal language that apps use to talk to each other. Don't let the "JavaScript" part fool you though — JSON works with pretty much every programming language out there.
Let's break it down in plain English, with plenty of examples along the way.
A Quick History Lesson
JSON was created by Douglas Crockford in the early 2000s. He wanted something simpler than XML for sending data back and forth between browsers and servers. The idea caught on fast — JSON was officially standardized as ECMA-404 in 2013 and later as RFC 8259 in 2017.
Today, over 90% of web APIs use JSON. It's not going anywhere.
What Does JSON Look Like?
Here's a simple example — a JSON object representing a person:
Pretty readable, right? That's the whole point. Let's look at the rules that make this work.
The Syntax Rules (They're Simple, Promise)
Data Types: JSON gives you six building blocks to work with: strings (always in double quotes), numbers, booleans (true/false), null, objects, and arrays. That's it — no dates, no functions, no special types.
Objects: These are your key-value pairs, wrapped in curly braces {}. Keys must be strings in double quotes. Here's an example of a nested object:
Arrays: Ordered lists wrapped in square brackets []. They can hold any mix of types:
One gotcha: JSON doesn't allow trailing commas. So {"name": "Sam",} will break your parser. This trips up a lot of people coming from JavaScript, where trailing commas are perfectly fine.
Why Developers Love JSON
There are a few reasons JSON won the data format wars:
- It's dead simple. Compare
{"name": "Jo"}with XML'sJo. Less typing, less noise. - Every language supports it. Python has
json.loads(), JavaScript hasJSON.parse(), Go hasencoding/json— you get the idea. Check out the MDN JSON docs for the JavaScript side. - It's lightweight. JSON payloads are typically 30-50% smaller than equivalent XML. That matters when you're sending millions of API responses a day.
- It maps naturally to code. A JSON object looks almost identical to a Python dictionary, a JavaScript object, or a Ruby hash. No translation layer needed.
Where You'll Find JSON in the Wild
- Web APIs: Hit almost any REST API and you'll get JSON back. Try it yourself — open your browser and visit
https://api.github.com/users/octocat. That's JSON. - Config files:
package.jsonfor Node.js,tsconfig.jsonfor TypeScript,settings.jsonfor VS Code — JSON is everywhere in developer tooling. - Databases: MongoDB stores data in BSON (binary JSON). PostgreSQL has native JSON column types. Even MySQL added JSON support.
- Data exchange: Microservices almost always talk to each other in JSON over HTTP.
JSON vs XML — The Short Version
XML still has its place (more on that in our XML article), but for most web dev work, JSON wins on readability, file size, and parsing speed. The one area where XML shines? Document-centric data with mixed content, schemas, and transformations.
Validating Your JSON
Even a tiny mistake — a missing comma, an extra quote, or a stray trailing comma — will cause JSON parsing to fail completely. There's no "partial parse" with JSON; it either works or it doesn't. That's why tools like our JSON Formatter and JSON Validator are so handy. Paste your JSON in, and you'll instantly see if something's off.
Common JSON Mistakes (And How to Fix Them)
After years of working with JSON, here are the mistakes I see developers make over and over:
1. Single quotes instead of double quotes. This is valid JavaScript, but NOT valid JSON:
2. Trailing commas. JavaScript allows them, JSON does not:
3. Comments. JSON has no comment syntax. If you need comments in config files, consider using JSONC (JSON with Comments, supported by VS Code) or switch to YAML.
4. Unquoted keys. In JavaScript you can write {name: "Sarah"}, but in JSON every key must be a quoted string: {"name": "Sarah"}.
5. Using undefined. JavaScript's undefined doesn't exist in JSON. Use null instead.
Working with JSON in Different Languages
One of JSON's biggest strengths is universal language support. Here's how parsing and serializing looks across popular languages:
Notice how similar the APIs are? parse/loads to read, stringify/dumps to write. Most languages follow this same pattern.
JSON Performance Tips
When you're dealing with large JSON payloads, performance starts to matter. Here are some practical tips:
- Minify for production. Removing whitespace from JSON can reduce file size by 10-30%. Our JSON Minifier does this in one click.
- Use streaming parsers for large files. If your JSON file is hundreds of megabytes, don't load it all into memory. Libraries like
JSONStream(Node.js) orijson(Python) parse incrementally. - Avoid deeply nested structures. Every level of nesting adds parsing overhead. If you find yourself nesting more than 4-5 levels deep, consider flattening your data model.
- Consider binary alternatives for extreme cases. For very high-throughput systems, formats like MessagePack, BSON, or Protocol Buffers can offer 2-5x smaller payloads and faster parsing. But you lose human readability, so this is a tradeoff.
JSON in Real-World API Design
Let's look at how real APIs structure their JSON responses. Here's a common pattern for paginated API responses:
And here's a common error response pattern:
These patterns are so common that you'll see them in almost every well-designed REST API. Following conventions like these makes your API easier for other developers to understand.
JSON Quick Reference
Here's a cheat sheet of everything you can put in a JSON document:
| Type | Example | Notes |
| String | "hello" | Must use double quotes |
| Number | 42, 3.14, -1, 2.5e10 | No leading zeros, no hex |
| Boolean | true, false | Lowercase only |
| Null | null | Lowercase only |
| Object | {"key": "value"} | Keys must be quoted strings |
| Array | [1, 2, 3] | Can mix types |
Try It Yourself
Ready to put this knowledge to use? Here are the tools you'll want bookmarked:
- JSON Formatter — Paste messy JSON and get it beautifully formatted with proper indentation.
- JSON Validator — Quickly check if your JSON is syntactically valid and get clear error messages when it's not.
- JSON Minifier — Strip whitespace from your JSON for production payloads.
JSON might seem simple on the surface, but mastering its quirks and best practices will save you countless hours of debugging. Now go build something great!