·8 min read

What is JSON? A Complete Guide for Beginners

JSON is everywhere — in APIs, config files, databases, and more. Here's everything you need to know about the most popular data interchange format on the web.

What is JSON?

JSON stands for JavaScript Object Notation. It is a lightweight, text-based data interchange format that is easy for humans to read and write, and easy for machines to parse and generate.

Despite having "JavaScript" in its name, JSON is a language-independent format. It is supported natively or through libraries in virtually every modern programming language including Python, Java, C#, Go, Ruby, PHP, and many more.

JSON is built on two universal data structures:

  • Objects — a collection of key/value pairs (like a dictionary or hash map)
  • Arrays — an ordered list of values

A Brief History of JSON

JSON was popularized by Douglas Crockfordin the early 2000s. He didn't invent the format so much as discover and formalize the subset of JavaScript literal syntax that was already being used informally for data exchange.

JSON was standardized as ECMA-404 in 2013 and described in RFC 8259 by the IETF. Its simplicity helped it rapidly replace XML as the dominant format for web APIs and configuration files.

JSON Syntax Rules

JSON has a very simple syntax with just a few rules:

  • Data is written as key/value pairs, separated by a colon
  • Keys must be strings wrapped in double quotes (single quotes are not valid)
  • Data items are separated by commas
  • Curly braces {} hold objects
  • Square brackets [] hold arrays
  • No trailing commas are allowed
  • No comments are allowed in standard JSON

JSON Data Types

JSON supports six data types:

TypeDescriptionExample
StringText wrapped in double quotes"hello"
NumberInteger or floating point42, 3.14
BooleanTrue or false valuetrue, false
NullEmpty/no valuenull
ObjectKey/value pairs in curly braces{"a": 1}
ArrayOrdered list in square brackets[1, 2, 3]

Note that JSON does not support undefined, functions, dates, or special number values like NaN or Infinity.

JSON Example

Here is a practical example of a JSON object representing a user profile:

{
  "name": "Jane Smith",
  "age": 28,
  "email": "jane@example.com",
  "isVerified": true,
  "address": {
    "street": "123 Main St",
    "city": "San Francisco",
    "state": "CA",
    "zip": "94102"
  },
  "hobbies": ["reading", "hiking", "photography"],
  "subscription": null
}

This example demonstrates strings, numbers, booleans, nested objects, arrays, and null values — all the JSON data types in action.

JSON vs XML

Before JSON became mainstream, XMLwas the standard format for data interchange. Here's how they compare:

FeatureJSONXML
ReadabilityVery easy to readVerbose, harder to scan
File sizeSmallerLarger due to tags
ParsingNative in JavaScriptRequires a parser
Data typesStrings, numbers, booleans, nullEverything is a string
CommentsNot supportedSupported
SchemaJSON Schema (optional)XSD, DTD

JSON won the popularity contest primarily because it is simpler, lighter, and maps naturally to the data structures used in most programming languages.

Where is JSON Used?

JSON is used extensively across the software industry:

  • REST APIs — The vast majority of web APIs use JSON as their request and response format
  • Configuration files — Tools like npm (package.json), TypeScript (tsconfig.json), and VS Code use JSON for config
  • NoSQL databases — Databases like MongoDB and CouchDB store data as JSON-like documents
  • Web storage — Browsers use localStorage and sessionStorage with JSON serialization
  • Data interchange — Microservices and distributed systems communicate using JSON messages
  • Logging — Structured logging formats often use JSON for easy parsing and analysis

Common JSON Mistakes

Even experienced developers make these JSON errors:

❌ Using single quotes

{ 'name': 'John' }

JSON requires double quotes for both keys and string values.

❌ Trailing commas

{ "a": 1, "b": 2, }

The comma after the last item is not valid JSON.

❌ Unquoted keys

{ name: "John" }

Keys must always be wrapped in double quotes.

❌ Comments in JSON

{ "name": "John" // this is a comment }

Standard JSON does not support comments. Use JSONC or JSON5 if you need them.

Working with JSON

In JavaScript, you can parse and create JSON using two built-in methods:

// Parse a JSON string into a JavaScript object
const data = JSON.parse('{"name": "Jane", "age": 28}');
console.log(data.name); // "Jane"

// Convert a JavaScript object to a JSON string
const json = JSON.stringify({ name: "Jane", age: 28 });
console.log(json); // '{"name":"Jane","age":28}'

// Pretty-print with 2-space indentation
const pretty = JSON.stringify(data, null, 2);
console.log(pretty);

When working with JSON data, it's essential to validate and format it properly. Malformed JSON can cause silent parsing errors that are hard to debug.

Format & Validate Your JSON

Use our free JSON Formatter tool to format, validate, and minify your JSON data instantly — right in your browser with no data uploaded to any server.

Try JSON Formatter →

References

  1. ECMA International. (2017). ECMA-404: The JSON Data Interchange Syntax, 2nd Edition. https://ecma-international.org/publications-and-standards/standards/ecma-404/
  2. Bray, T. (2017). The JavaScript Object Notation (JSON) Data Interchange Format. RFC 8259, IETF. https://datatracker.ietf.org/doc/html/rfc8259
  3. Mozilla Developer Network. JSON — JavaScript. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON
  4. Crockford, D. Introducing JSON. https://www.json.org/json-en.html
  5. JSON Schema. JSON Schema Specification. https://json-schema.org/specification