JSON is the most widely used data format on the internet. Every app, web page, and API call you encounter almost certainly uses it. Understanding JSON is one of the highest-leverage skills for anyone working in technology.
What JSON Is
JSON (JavaScript Object Notation) is a plain-text format representing structured data as key-value pairs. It is language-independent and natively supported in Python, Java, PHP, Go, Ruby, and every other major language. Two top-level structures: objects (curly braces, key-value pairs) and arrays (square brackets, ordered values).
Strict Syntax Rules
- All string keys must use double quotes β single quotes are invalid
- No trailing comma after the last item in an object or array
- Numbers are unquoted; booleans are lowercase
true/false; null isnull - Backslashes and double quotes inside strings must be escaped
Most Common Errors
The trailing comma is the #1 JSON error. It is legal in JavaScript but strictly invalid in JSON. Single quotes instead of double quotes is #2. Unescaped special characters inside strings are #3.
Validating and Formatting
UltraToolkit's JSON Formatter validates, formats, and minifies JSON in your browser β no data sent anywhere. Use Validate mode to find the exact character position of errors. Use Format to make nested structures readable. Use Minify to reduce payload size for transmission.
JSON vs XML
JSON replaced XML in most web contexts because it is more compact, easier to read, faster to parse, and maps naturally to programming language data structures. XML persists in legacy enterprise systems and specific standards (RSS, Office formats).
JSON: The Language APIs Use to Talk
JSON (JavaScript Object Notation) has become the universal data interchange format for web APIs, configuration files, and data storage because it achieves an ideal balance between human readability and machine parseability. Unlike its predecessor XML (which uses verbose tags like
JSON was formalised by Douglas Crockford in the early 2000s based on a subset of JavaScript's object literal syntax. The format was standardised as ECMA-404 in 2013 and RFC 8259 in 2017. Despite its origins in JavaScript, JSON is language-agnostic β every major programming language has built-in or standard-library JSON parsing: json.loads/json.dumps in Python, JSON.parse/JSON.stringify in JavaScript, Gson/Jackson in Java, System.Text.Json in C#, encoding/json in Go, serde_json in Rust.
The Six JSON Data Types
JSON supports exactly six data types. String: text enclosed in double quotes. Strings can contain any Unicode character and use backslash escape sequences for special characters (\n for newline, \t for tab, \" for a literal double quote, \\ for a backslash). Number: integer or floating-point numeric values with no quotes. JSON does not distinguish between integers and floats β 42 and 42.0 are both valid JSON numbers, though parsers may handle them differently. Boolean: exactly true or false (lowercase), no quotes. Null: exactly null (lowercase), representing the intentional absence of a value. Object: a collection of key-value pairs enclosed in curly braces, where keys must be strings. Array: an ordered list of values enclosed in square brackets.
Every value in JSON must be one of these six types β including values nested inside objects and arrays. Objects can nest other objects, arrays can contain objects, and any combination is valid. The depth of nesting is theoretically unlimited (in practice limited by parser recursion limits). A JSON document that is a single string ('Hello, World') is valid. A JSON document that is a single number (42) is valid. A JSON document that is a single array ([1,2,3]) is valid. The root element does not need to be an object, though most API responses use an object as the root to allow adding more fields in the future.
Common JSON Syntax Errors
JSON has strict syntax rules that differ from JavaScript object literal syntax in important ways. Trailing commas are invalid JSON β {name: 'John', age: 30,} is not valid JSON because of the comma after 30. This is a very common error when manually editing JSON, because JavaScript, Python dictionaries, and most modern programming languages allow trailing commas. Keys must be strings in double quotes β {name: 'John'} is invalid JSON (name is not quoted); {'name': 'John'} uses single quotes which are also invalid; {"name": "John"} is correct. All string values must use double quotes, not single quotes.
Numbers must not have leading zeros β 042 is invalid JSON. Numbers must not have trailing decimal points β 42. is invalid JSON. The special float values Infinity, -Infinity, and NaN that are valid in JavaScript are not valid JSON β they must be represented as strings or null. Comments are not allowed in JSON at all β neither // nor /* */ style comments are valid JSON. Many developers discover this when a JSON configuration file with comments (common in developer tool configs) causes a parse error.
Reading and Writing JSON in JavaScript
JSON.parse() converts a JSON string into a JavaScript value. JSON.stringify() converts a JavaScript value into a JSON string. JSON.stringify accepts two optional arguments: a replacer (a function or array that filters which properties are included in the output) and a space argument (a number of spaces or a string for indentation, making the output human-readable). JSON.stringify(data, null, 2) produces pretty-printed JSON with 2-space indentation β the format used by most developer tools and log output.
Dates present a particular challenge in JSON because JSON has no date type. Dates are typically serialised as ISO 8601 strings (2024-06-15T14:30:00Z) or as Unix timestamps (milliseconds since January 1, 1970). JSON.stringify automatically converts JavaScript Date objects to ISO 8601 strings. JSON.parse does not automatically convert ISO 8601 strings back to Date objects β the parsed value is a string, and the application must explicitly convert it using new Date(parsedString). This asymmetry is a common source of bugs when round-tripping dates through JSON serialisation.
JSON in REST API Design
REST APIs use JSON as the request and response body format, transmitted with the Content-Type: application/json HTTP header. A well-designed JSON API response includes the requested data and enough metadata for the client to understand the response without additional documentation. Common patterns: envelope responses ({data: {...}, meta: {...}, errors: [...]}) that separate the payload from metadata, consistent error response format with an error code and human-readable message, and ISO 8601 timestamps for all date and time values.
JSON API versioning is a consideration when the response format changes over time. Adding new fields to a JSON response is a backward-compatible change β existing clients can ignore unknown fields. Removing or renaming existing fields, or changing field types, are breaking changes that require API version management. The principle of being conservative in what you send and liberal in what you accept applies to JSON API design: send only documented fields, accept additional unknown fields gracefully.
Format, validate, and beautify JSON instantly with the UltraToolkit JSON Formatter. Syntax error highlighting, pretty-print, minify β all in your browser.
Try JSON Explained for Beginners for free
All 14 utilities are free, instant, and require no account or installation.
Open Tool β All Free Tools