Table of Contents
What Is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format. Despite its name, JSON is language-independent and is the dominant serialization format for REST APIs, configuration files, NoSQL databases (MongoDB, Firestore), and web application state management.
JSON was formally specified in RFC 8259 (formerly RFC 7159) and ECMA-404. Understanding the strict specification prevents parsing errors across different languages and platforms.
The 6 JSON Data Types
JSON supports exactly six data types:
- String: Unicode text enclosed in double quotes.
"hello world" - Number: Integer or floating-point. No leading zeros, no hex, no NaN/Infinity.
42,3.14,-7,2.5e10 - Boolean: Exactly
trueorfalse(lowercase only). - Null: Exactly
null(lowercase only). Represents absence of value. - Object: An unordered collection of key-value pairs. Keys must be strings.
{"name": "FreeToolkit", "version": 1} - Array: An ordered list of values.
[1, "two", true, null]
Everything in a valid JSON document must be one of these six types or a nested combination of them.
The 5 Most Common JSON Validation Errors
These are the errors that trip up developers most frequently:
-
Trailing commas: JavaScript allows trailing commas in arrays and objects, but JSON does NOT.
{"a": 1, "b": 2,}← INVALID. Remove the comma after the last value. -
Single quotes: JSON requires double quotes for all strings and keys.
{'name': 'test'}← INVALID. Use{"name": "test"}. -
Unquoted keys: JavaScript objects allow unquoted keys, but JSON requires every key to be a double-quoted string.
{name: "test"}← INVALID. Use{"name": "test"}. -
Comments: JSON does not support comments of any kind — no
//, no/* */.
If you need comments in configuration files, consider JSON5 or JSONC (non-standard extensions). -
Undefined and NaN: JavaScript's
undefined,NaN, andInfinityare not valid JSON values. Usenullinstead.
JSON vs YAML vs XML: When to Use Which
| Feature | JSON | YAML | XML |
|---|---|---|---|
| Readability | Good | Excellent (indentation-based) | Verbose (tag-heavy) |
| Comments | Not supported | Supported (#) | Supported (<!-- -->) |
| Data types | 6 types | Rich (dates, timestamps) | All text (typed via schema) |
| File size | Compact | Compact | Large (30–50% bigger) |
| Parsing speed | Very fast | Slower (complex spec) | Moderate |
| Primary use | APIs, web apps, config | Config files (Docker, K8s) | Enterprise, SOAP, legacy |
Rule of thumb: Use JSON for API communication and web application data. Use YAML for human-edited configuration files where comments are valuable. Avoid XML for new projects unless interfacing with legacy enterprise systems.
Formatting and Minifying JSON
Pretty-printing (formatting) adds indentation and line breaks to make JSON human-readable during development and debugging. This is essential when inspecting API responses, debugging database documents, or reviewing configuration files.
Minifying removes all unnecessary whitespace to produce the smallest possible payload. Minified JSON is used in production API responses and stored data to minimize bandwidth and storage costs.
FreeToolkit's JSON Formatter and JSON Validator run entirely in your browser's V8 engine — your API keys, tokens, and confidential data never leave your device.
Written by Dhaval Joshi. Have feedback or questions? Contact us at support@freetoolkit.online.