
What is JSON? JSON (JavaScript Object Notation) is a lightweight, text-based data format that uses key-value pairs and arrays to represent structured data. It is the most common format for sending and receiving data on the web—used by REST APIs, config files, and apps in every major programming language. JSON is human-readable when formatted, easy for machines to parse, and does not require a schema, which is why it has become the default choice for modern APIs and data exchange.
If you've ever opened a package.json, called a REST API, or worked with data from a server, you've already used JSON. This guide explains what JSON is, how its syntax works, the data types it supports, real-world examples, and where you'll encounter it—plus how to validate and format JSON online for free.
What is JSON? Definition and Basics
JSON stands for JavaScript Object Notation. It was popularized in the early 2000s as a simpler alternative to XML for sending data over the internet. Despite the name, JSON is not tied to JavaScript: it is a language-independent standard (ECMA-404 and RFC 8259) that can be used with Python, Java, C#, Go, and virtually any language.A JSON document is just text. It uses only a few rules: data is stored in objects (curly braces { }) and arrays (square brackets [ ]), with keys in double quotes and values that can be strings, numbers, booleans, null, or nested objects and arrays. There are no comments, no trailing commas, and no single quotes—which keeps the format small and easy to parse.

JSON Syntax Rules
To write valid JSON, follow these rules:"name" not name."hello" not 'hello'.// or / /.: between key and value, , between pairs or elements.Breaking any of these rules makes the JSON invalid. Use a JSON validator to check syntax, or a JSON fixer to auto-repair common mistakes.
JSON Data Types
JSON supports exactly six types:| Type | Example |
|---|---|
| String | "hello", "\"escaped\"" |
| Number | 42, 3.14, -1 |
| Boolean | true, false |
| Null | null |
| Object | { "key": "value" } |
| Array | [ 1, 2, "three" ] |
Simple JSON Examples
Object (key-value pairs):{
"name": "Alex",
"age": 28,
"active": true
}Array of items:
[
"apple",
"banana",
"cherry"
]Nested object and array (typical API response):
{
"user": {
"id": 1,
"email": "alex@example.com"
},
"tags": [ "admin", "editor" ]
}Where is JSON Used?
JSON is everywhere in modern software:package.json (Node.js), tsconfig.json, composer.json, and many app configs use JSON.
How to Read and Write JSON
In JavaScript, you useJSON.parse() to convert a JSON string into an object, and JSON.stringify() to convert an object back into a JSON string:// String → Object
const text = '{"name":"Alex","age":28}';
const obj = JSON.parse(text);
console.log(obj.name); // "Alex"// Object → String const jsonString = JSON.stringify(obj); console.log(jsonString); // '{"name":"Alex","age":28}'
In other languages you'll use similar APIs (e.g. json.loads / json.dumps in Python, JsonConvert in C#).
JSON vs XML and Other Formats
JSON is often compared to XML: both represent structured data as text. JSON is usually shorter, easier to read, and maps naturally to objects and arrays in most languages. XML supports attributes, namespaces, and comments, so it is still used in enterprise and SOAP APIs.Common JSON Mistakes
Beginners often hit these issues:{"a": 1,} is invalid. Remove the comma after the last property.{name: "Alex"} is invalid; use {"name": "Alex"}.\", \n, \uXXXX).Feature Comparison Table
| Feature | JSON | XML | YAML |
|---|---|---|---|
| Readability | Good | Moderate | Excellent |
| File Size | Small | Large | Smallest |
| Parsing Speed | Fast | Slower | Moderate |
| Comments Support | No | Yes | Yes |
| Schema Validation | JSON Schema | XSD, DTD | Limited |
| Browser Support | Native | Native | Requires library |

