Development

What Is JSON? A Complete Guide for Developers

By AZ Utils Editorial · · 12 min read

What Is JSON? A Complete Guide for Developers

If you have ever called a web API, edited a configuration file, or looked at how a modern app talks to its server, you have almost certainly seen JSON. It is the format that quietly powers most of the data exchange on the internet today. This guide explains what JSON is, the rules that govern it, how to read and write it in code, where it is used, and the mistakes that trip people up — with practical examples throughout.

It is written for developers and engineers who want a solid reference, students learning the fundamentals, and technical beginners who keep seeing JSON and want to truly understand it.

What Is JSON?

JSON stands for JavaScript Object Notation. It is a lightweight, text-based format for storing and exchanging structured data. Despite the name, JSON is language-independent: although its syntax comes from JavaScript object literals, virtually every programming language — Python, Java, C#, Go, PHP, Ruby and more — can read and write it.

At its heart, JSON represents data as key/value pairs and ordered lists, which map naturally onto the objects/dictionaries and arrays that almost every language already has. That natural mapping is a big part of why JSON became so popular: a server can serialize an object to JSON text, send it across the network, and a client in a completely different language can parse it straight back into its own native structures.

A minimal JSON document looks like this:

{
  "name": "Ada Lovelace",
  "age": 36,
  "isMathematician": true
}

That is a JSON object with three keys. Simple, human-readable, and machine-parseable — the combination that made JSON the default.

In short: JSON is a lightweight, text-based, language-independent format for exchanging structured data as key/value pairs and arrays. It is the de facto standard for web APIs and configuration.

Why JSON Became the Standard

Before JSON, XML was the dominant data-interchange format. XML is powerful but verbose, and parsing it in a browser was cumbersome. JSON arrived with three advantages that fit the web perfectly:

  • It is compact. Less boilerplate than XML means smaller payloads and faster transfers.
  • It maps directly to native data types. Strings, numbers, booleans, arrays and objects all have first-class representations, so there is little translation work.
  • It is trivial to parse in the browser. JavaScript can turn JSON text into objects in a single call, with no external library.

As single-page apps and REST APIs took off, JSON became the natural choice, and today it dominates API responses, configuration files, NoSQL document stores and countless other places. (For a full head-to-head, see JSON vs XML.)

JSON Syntax: The Core Rules

JSON has a small, strict grammar. Learn these rules and you can read or write any JSON document.

The six data types

A JSON value must be one of exactly six types:

  • String — text in double quotes: "hello". (Single quotes are not allowed.)
  • Number — an integer or decimal: 42, 3.14, -7, 2.5e3. (No leading zeros, no NaN or Infinity.)
  • Booleantrue or false (lowercase).
  • null — represents an empty or unknown value.
  • Object — an unordered set of key/value pairs in curly braces { }.
  • Array — an ordered list of values in square brackets [ ].

Objects and arrays

An object wraps comma-separated "key": value pairs in braces. Keys must be strings in double quotes:

{
  "id": 101,
  "title": "Intro to JSON",
  "published": true
}

An array is an ordered list of values, which can be of mixed types:

[ "red", "green", "blue" ]

[ 1, "two", true, null ]

Objects and arrays can be nested to any depth, which is how JSON represents complex, hierarchical data:

{
  "user": {
    "name": "Grace Hopper",
    "roles": ["admin", "engineer"],
    "active": true
  },
  "loginCount": 274
}

The rules that matter most

  • Strings and keys use double quotes, never single quotes.
  • Separate pairs and array items with commas — but never after the last one (no trailing commas).
  • JSON has no comments. There is no // or /* */.
  • Whitespace between tokens is ignored, so JSON can be pretty-printed or minified without changing its meaning.

Featured-snippet target: JSON syntax uses key/value pairs inside curly braces for objects and ordered values inside square brackets for arrays. Keys and strings use double quotes, values can be strings, numbers, booleans, null, objects or arrays, and trailing commas and comments are not allowed.

A Complete, Realistic JSON Example

Here is the kind of JSON you might receive from a web API — an object containing metadata and a nested array of records:

{
  "status": "ok",
  "page": 1,
  "totalResults": 2,
  "results": [
    {
      "id": 1,
      "title": "Getting Started with APIs",
      "tags": ["api", "beginner"],
      "rating": 4.8,
      "draft": false
    },
    {
      "id": 2,
      "title": "Advanced Caching",
      "tags": ["performance", "cache"],
      "rating": 4.6,
      "draft": true
    }
  ]
}

Notice how every value has a clear type, how the array holds two similarly-shaped objects, and how the structure reads almost like plain English. When a payload like this gets large or minified into one line, a JSON formatter makes it readable again by re-indenting it.

How to Work with JSON in Code

Reading and writing JSON usually involves two operations: parsing (text → native object) and serializing or stringifying (native object → text).

JavaScript

JavaScript has built-in JSON support — no library required:

// Parse: JSON text -> JavaScript object
const text = '{ "name": "Ada", "age": 36 }';
const obj = JSON.parse(text);
console.log(obj.name); // "Ada"

// Stringify: JavaScript object -> JSON text
const user = { name: "Grace", roles: ["admin"] };
const json = JSON.stringify(user);          // compact
const pretty = JSON.stringify(user, null, 2); // indented by 2 spaces

When you call a web API with fetch, the response body is JSON text that you parse with response.json():

const res = await fetch("/api/users/1");
const data = await res.json(); // parsed object
console.log(data.name);

Python

Python's standard library includes the json module:

import json

# Parse: JSON text -> Python dict
text = '{ "name": "Ada", "age": 36 }'
obj = json.loads(text)
print(obj["name"])  # Ada

# Serialize: Python dict -> JSON text
user = { "name": "Grace", "roles": ["admin"] }
compact = json.dumps(user)
pretty = json.dumps(user, indent=2)

The pattern is the same across languages: a parse function and a serialize function. The data types map cleanly — JSON objects become dictionaries/maps, arrays become lists, and the primitives map to their native equivalents.

JSON vs JavaScript Objects: A Subtle but Important Difference

Because JSON came from JavaScript, developers often blur the two — but they are not the same thing, and the difference causes real bugs.

A JavaScript object is a live, in-memory data structure you can manipulate in code. JSON is text — a string that represents data. You convert between them with JSON.parse and JSON.stringify.

JSON is also stricter than a JavaScript object literal. The following is a perfectly valid JavaScript object but is not valid JSON:

// Valid JavaScript object literal — NOT valid JSON
const obj = {
  name: 'Ada',        // single quotes + unquoted key
  greet() { return 'hi'; }, // a method/function
  updated: new Date(),      // a Date instance
  note: undefined,          // undefined value
};

To be valid JSON, the same data must use double-quoted keys and strings, and may only contain the six JSON types — no functions, no undefined, no Date objects:

{
  "name": "Ada",
  "updated": "2026-01-15T09:30:00Z"
}

This is also why JSON.stringify silently drops values it cannot represent: functions and undefined properties simply disappear from the output, and a Date is converted to an ISO string. Knowing this prevents the classic surprise of "my object had a property, but it vanished after a round-trip through JSON."

Dates, Numbers and Other Edge Cases

JSON's small type system is a strength, but it has a few sharp edges worth knowing:

  • There is no date type. Dates are conventionally stored as ISO 8601 strings like "2026-01-15T09:30:00Z", and each side is responsible for parsing them back into real date objects.
  • Numbers have precision limits. JSON numbers are typically read as 64-bit floating point, so very large integers (beyond 2^53) can lose precision. For things like big IDs, send them as strings to be safe.
  • No NaN or Infinity. These are not valid JSON numbers; serializers usually output null in their place.
  • Key order is not guaranteed. JSON objects are conceptually unordered, so never rely on the position of keys — use an array if order matters.
  • Duplicate keys are undefined behaviour. Most parsers keep the last one, but you should never produce JSON with duplicate keys.

When you receive JSON with any of these characteristics, a quick pass through a formatter to inspect the structure and a validator to confirm it parses will save you debugging time.

Where JSON Is Used

  • Web APIs. The vast majority of REST APIs send and receive JSON. It is the lingua franca between front-end apps and back-end services.
  • Configuration files. Tools and projects use JSON for settings — package.json, tsconfig.json, app manifests and more.
  • Databases. Document databases like MongoDB store records as JSON-like documents, and relational databases now have native JSON column types.
  • Data storage and logs. JSON Lines (one JSON object per line) is a common format for streaming logs and datasets.
  • Inter-service messaging. Microservices frequently exchange JSON messages over HTTP or queues.

Because it is everywhere, being comfortable reading, writing and debugging JSON is a core skill for any developer.

Try Our Free JSON Tools

Working with JSON is far easier with the right tools. Both of ours run entirely in your browser, so your data never leaves your device:

  • JSON Formatter — beautify and indent messy or minified JSON, or compact it back down.
  • JSON Validator — check whether your JSON is valid and get the exact line of any error.

👉 Format your JSON now →

Common JSON Mistakes

Most "invalid JSON" errors come from a handful of recurring slips:

  1. Trailing commas. A comma after the last item — [1, 2, 3,] or a final "key": value, — is invalid in JSON, even though it is allowed in JavaScript.
  2. Single quotes. { 'name': 'Ada' } is not valid JSON; both keys and string values require double quotes.
  3. Unquoted keys. { name: "Ada" } is a JavaScript object literal, not JSON — keys must be quoted strings.
  4. Comments. Adding // note or /* note */ breaks JSON; it has no comment syntax.
  5. Wrong types. Writing a number as a string ("age": "36") when a number is expected, or using True/None (Python style) instead of true/null.
  6. Unescaped special characters. Literal newlines, tabs or unescaped double quotes inside a string must be escaped: "line1\nline2", "He said \"hi\"".
  7. A stray non-JSON wrapper. Accidentally including a leading )]}' anti-hijacking prefix, a BOM, or HTML from an error page in what you thought was a JSON response.

When a parser rejects your JSON, paste it into the JSON validator — it points to the exact location of the problem so you do not have to hunt for the missing comma by eye.

Best Practices

  • Validate before you ship. Run config files and fixtures through a validator to catch syntax errors early.
  • Use consistent key naming. Pick one convention — usually camelCase for web APIs or snake_case for some back-ends — and stick to it across the project.
  • Keep structures predictable. Give the same kind of record the same shape every time, so consumers can rely on it.
  • Prefer arrays for lists, objects for keyed data. Do not fake a list with numbered keys like {"0":..., "1":...}.
  • Mind the types. Send numbers as numbers and booleans as booleans, not as strings, so clients do not have to convert.
  • Pretty-print for humans, minify for machines. Indent JSON in docs and debugging; compact it for production payloads to save bytes.
  • Never trust external JSON blindly. Always parse inside a try/catch (or equivalent) and validate the structure before using it.

Frequently Asked Questions

What does JSON stand for?

JSON stands for JavaScript Object Notation. It is a lightweight, text-based format for storing and exchanging structured data, and it is language-independent despite originating from JavaScript.

Is JSON a programming language?

No. JSON is a data format, not a programming language. It only describes data; it has no logic, functions or execution. Programming languages read and write JSON using parse and serialize functions.

What data types does JSON support?

JSON supports six value types: string, number, boolean, null, object (key/value pairs) and array (ordered list). Objects and arrays can be nested to represent complex data.

Can JSON have comments?

No. Standard JSON does not support comments. If you need annotated configuration, some tools accept a relaxed superset like JSON5 or JSONC, but strict JSON has no comment syntax.

Why is my JSON invalid?

The most common causes are trailing commas, single quotes instead of double quotes, unquoted keys, comments, or unescaped special characters. A JSON validator will point to the exact line of the error.

What is the difference between JSON.parse and JSON.stringify?

JSON.parse converts JSON text into a JavaScript object; JSON.stringify converts a JavaScript object into JSON text. Most languages offer the same pair of operations under different names, such as json.loads and json.dumps in Python.

Is JSON better than XML?

For web APIs and configuration, JSON is usually preferred because it is more compact, maps to native data types and parses easily in browsers. XML remains useful for documents and systems that need its richer features.

Summary

JSON is the backbone of modern data exchange: a lightweight, text-based, language-independent format built from key/value objects and ordered arrays. Its strict but small set of rules — double-quoted keys and strings, six value types, no trailing commas, no comments — makes it both human-readable and reliably machine-parseable. You read it with a parse function and write it with a serialize function, in any language you like, and you will meet it in APIs, config files, databases and logs every day.

Master the syntax, watch out for the common mistakes, follow the best practices, and lean on a formatter and validator when things get messy — and JSON becomes one of the simplest, most dependable tools in your kit.

Perhaps the most valuable perspective to carry away is that JSON's strictness, which can feel like a nuisance when a stray comma breaks a payload, is precisely the source of its reliability. Because the format admits no ambiguity and no dialect, a JSON document means exactly the same thing to every parser in every language, which is what allows wildly different systems to exchange data flawlessly. The few rules you must respect are the price of that universal interoperability, and they are a small price indeed. Learn them once, treat JSON as the strict data format it is rather than the flexible code it resembles, and it will serve you dependably across every corner of modern software you work in.

👉 Format and validate your JSON with our free tools →

AZ Utils Editorial

AZ Utils Editorial

Finance & web-tools writer

AZ Utilis writes practical, plain-English guides on calculators, finance and everyday web tools, drawing on years of experience helping beginners and small businesses get the numbers right.

Development

How to Format JSON (Beautify & Minify)

How to format JSON — beautify it for readability or minify it for production — in tools, editors, the command line and code, with the why behind each.

AZ Utils Editorial · · 10 min read