JavaScript Object Notation (JSON) is a lightweight data-interchange format that is easy for humans to read and write, and easy for machines to parse and generate. Originally popularized by Douglas Crockford, JSON has entirely replaced XML in modern RESTful APIs and GraphQL endpoints.
What Is JSON and Where Did It Come From?
JSON was formally specified by Douglas Crockford in the early 2000s as a subset of JavaScript. While the format is based on JavaScript object literal syntax, it is language-independent—parsers exist for Python, Java, Go, Ruby, PHP, C#, and virtually every other programming language. JSON was officially standardized as ECMA-404 and RFC 8259.
Before JSON, XML dominated web service communication. XML is verbose, requires closing tags for every element, and is harder to read and parse. JSON replaced XML in most API contexts because its syntax maps naturally to the data structures of most programming languages: objects, arrays, strings, numbers, booleans, and null.
Strict Syntax Rules
Unlike raw JavaScript objects, JSON syntax is incredibly strict. A single misplaced comma can crash a data pipeline.
- Double Quotes: All keys and string values must be enclosed in double quotes (
"). Single quotes are strictly invalid in JSON. - No Trailing Commas: The last item in an array or object must not be followed by a comma. Many JSON parsers will throw an error.
- Data Types: JSON only supports strings, numbers, objects, arrays,
true,false, andnull. Functions,undefined,Infinity, andNaNare not valid JSON. - Unicode: All JSON text must be encoded in UTF-8, UTF-16, or UTF-32.
- No Comments: Unlike YAML or JavaScript objects, JSON does not support comments of any kind.
Common JSON Errors and How to Fix Them
| Error | Cause | Fix |
|---|---|---|
| Unexpected token ' | Single-quoted string | Replace ' with " |
| Unexpected token } | Trailing comma before } | Remove last comma |
| Unexpected end of JSON | Unclosed bracket or brace | Close all [ and { |
| undefined is not valid | undefined value in payload | Replace with null |
Debugging Broken JSON
When integrating with third-party APIs, you'll often encounter minified, unreadable JSON payloads. Manually formatting these is nearly impossible. Instead, developers rely on automated parsers. By pasting your raw payload into our Advanced JSON Formatter, you can instantly prettify the data and highlight syntax errors on specific lines.
JSON Schema: Validating Structure
JSON Schema is a vocabulary for annotating and validating JSON documents. It allows you to define the expected structure of a JSON payload—required fields, data types, minimum/maximum values, and patterns. This is used in API documentation tools like Swagger/OpenAPI, configuration validators, and form validation libraries.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["name", "age"],
"properties": {
"name": { "type": "string" },
"age": { "type": "integer", "minimum": 0 }
}
}Converting Between JSON and Other Formats
Data often needs to move between formats. Our developer tools handle the most common conversions:
- JSON to CSV: Flatten nested JSON for spreadsheet analysis using our JSON to CSV Converter.
- CSV to JSON: Transform spreadsheet exports into API-ready JSON with our CSV to JSON Converter.
- YAML to JSON: Convert Kubernetes and Docker configuration files using our YAML to JSON Converter.
- XML to JSON: Migrate legacy SOAP service payloads using our XML to JSON Converter.
JSON vs. YAML vs. XML: Format Showdown
| Feature | JSON | YAML | XML |
|---|---|---|---|
| Human Readable | ✅ Good | ✅ Excellent | ⚠️ Verbose |
| Comments | ❌ No | ✅ Yes | ✅ Yes |
| API Standard | ✅ Dominant | ⚠️ Config only | ⚠️ Legacy |
| File Size | ✅ Small | ✅ Small | ❌ Large |
| Schema Validation | ✅ JSON Schema | ✅ JSON Schema | ✅ XSD |
Frequently Asked Questions
Can JSON have comments?
No. JSON does not support comments. If you need comments in a configuration file, consider YAML or JSON5 (a superset of JSON). Many build tools like Webpack support JSONC (JSON with Comments) for their config files.
What is the difference between JSON.parse() and JSON.stringify()?
JSON.parse() converts a JSON string into a JavaScript object. JSON.stringify() converts a JavaScript object into a JSON string. These are the two fundamental JSON operations in any JavaScript application.
Is JSON case-sensitive?
Yes. JSON keys are case-sensitive. "Name" and "name" are treated as two different keys. This is a common source of API integration bugs.
