JSON (JavaScript Object Notation)
JSON is an open, text-based data interchange format standardized in RFC 8259, designed for human-readable and machine-parseable data transmission.
JSON (JavaScript Object Notation) is a lightweight, language-agnostic, text-based data interchange format standardized under RFC 8259 and ECMA-404. It structures serialized data into human-readable collections of attribute-value pairs (objects) and ordered sequences of values (arrays). JSON is the ubiquitous standard for REST APIs, JSON Web Tokens (JWT), configuration files, NoSQL document databases, and client-server communications across modern software architectures.
Format, validate, repair, and beautify your payloads with our interactive JSON Formatter tool or generate type definitions with JSON to C#, JSON to Go, JSON to Rust, JSON to TypeScript, and JSON to Dart. Learn more about static typing in our C# Class Glossary Entry, Go Structs Glossary Entry, TypeScript Glossary Entry, and Serde Glossary Entry.
Technical Specifications at a Glance
| Specification | Details |
|---|---|
| Official Standards | IETF RFC 8259 / ECMA-404 / ISO/IEC 21778 |
| MIME Media Type | application/json |
| Standard File Extension | .json |
| Character Encoding | UTF-8 (Strictly mandated by RFC 8259) |
| Language Dependency | 100% Independent (Parsers exist for every major language) |
| Uniform Resource Identifier | RFC 6901 (JSON Pointer) / RFC 9535 (JSONPath) |
The 6 Supported JSON Data Types
JSON defines exactly six data types. Any payload containing types outside this list is invalid JSON:
| Data Type | Syntax Rules | Example |
|---|---|---|
| String | Sequence of Unicode characters enclosed in strict double quotes ("..."). Escaping with \ is supported for \", \\, \/, \b, \f, \n, \r, \t, and \uXXXX. |
"title": "DevFlow Tools" |
| Number | Decimal number (integer or floating-point). Scientific notation (e or E) is valid. Hexadecimal, NaN, and Infinity are forbidden. |
"latencyMs": 42.5, "exp": 1e6 |
| Boolean | Literal lowercase true or false without quotation marks. |
"isActive": true |
| Null | Literal lowercase null denoting empty or absent values. |
"deletedAt": null |
| Object | Unordered set of comma-separated key-value pairs wrapped in curly braces ({}). Keys must be double-quoted strings. |
{"id": 1, "role": "admin"} |
| Array | Ordered sequence of zero or more comma-separated values wrapped in square brackets ([]). May contain mixed data types. |
["TypeScript", 2026, false] |
{
"api": "DevFlow",
"version": 2.0,
"stable": true,
"endpoints": ["/tools", "/glossary"],
"meta": {
"author": "Antigravity Team",
"license": "MIT"
}
}
Valid vs Invalid JSON: Top 4 Developer Pitfalls
Many syntax errors occur when developers treat JSON like JavaScript object literals:
| Syntax Feature | JavaScript Object Literal | Strict JSON (RFC 8259) | Fix / Proper JSON Syntax |
|---|---|---|---|
| Trailing Commas | Allowed ([1, 2,]) |
Syntax Error | Remove the trailing comma after the final element. |
| Quotation Style | Single quotes allowed ('name') |
Syntax Error | Always use double quotes ("name"). |
| Unquoted Object Keys | Allowed ({ name: "John" }) |
Syntax Error | Keys must be quoted: { "name": "John" }. |
| Comments | // or /* */ allowed |
Syntax Error | Remove comments or use dedicated config formats like JSONC/TOML. |
Format Comparison: JSON vs XML vs YAML vs Protocol Buffers
| Feature | JSON | XML | YAML | Protocol Buffers (Protobuf) |
|---|---|---|---|---|
| Readability | High | Medium (Verbose tags) | Very High | Binary (Requires .proto schema) |
| Parsing Speed | Very Fast (Native C++) | Slow (DOM/SAX parsing) | Moderate | Ultra-Fast (Pre-compiled binary) |
| Payload Size | Compact | Heavy | Compact | Ultra-Compact (Compressed binary) |
| Typing System | 6 Primitive Types | Strings only (Untyped) | Rich Types | Strongly Typed Schema |
| Schema Validation | JSON Schema | XSD / DTD | JSON Schema / Custom | Protocol Buffers Compiler (protoc) |
| Primary Domain | Web APIs & Client Apps | Enterprise SOAP & RSS | DevOps (K8s, CI/CD) | High-throughput Microservices (gRPC) |
Code Examples: Parsing & Serialization
Modern JavaScript / TypeScript
// 1. Serialization with Formatting and Replacer
const config = {
service: "Gateway",
port: 8080,
secretToken: "hidden_token",
created: new Date(),
};
// Pretty-print with 2 spaces and omit sensitive keys
const jsonString = JSON.stringify(config, (key, value) => {
if (key === 'secretToken') return undefined; // Strips key from output
return value;
}, 2);
// 2. Safe Parsing with Error Handling
try {
const parsed = JSON.parse(jsonString);
console.log("Parsed service:", parsed.service);
} catch (error) {
console.error("Malformed JSON received:", (error as Error).message);
}
Python 3
import json
data = {
"appName": "DevFlow",
"metrics": {"requests": 1500, "errors": 0},
"flags": [True, False, None]
}
# Serialize with proper UTF-8 and clean indentation
json_str = json.dumps(data, indent=2, ensure_ascii=False)
# Parse JSON string back to native dict
parsed_dict = json.loads(json_str)
Frequently Asked Questions
Why doesn't standard JSON support comments?
Douglas Crockford (the creator of JSON) intentionally excluded comments from the RFC standard to prevent developers from parsing custom compiler directives or parser-dependent instructions inside data payloads. For developer configuration files that require comments, use variants like JSON5 or JSONC (JSON with Comments).
How should 64-bit integers (BigInt) be handled in JSON?
The IEEE 754 double-precision floating-point specification used by JavaScript limits safe integers to $\pm(2^{53} - 1)$ (9,007,199,254,740,991). Any 64-bit integer exceeding this range (such as database snowflake IDs or high-resolution timestamps) will suffer rounding corruption. Best practice is to serialize large integers as strings in JSON payloads ("id": "18446744073709551615").
What is the difference between JSON and JSON Lines (JSONL / NDJSON)?
Standard JSON requires an entire array [...] to be loaded and parsed in memory at once. JSON Lines (JSONL) structures data such that each line is an independent, complete JSON object separated by a newline (\n). JSONL is optimal for streaming event logs, machine learning datasets, and big data pipelines because it can be read line-by-line without buffering giant files.
How do I convert JSON structures to code types automatically?
Manually writing TypeScript interfaces or Zod validation schemas for large API responses is error-prone. You can paste any JSON payload into our JSON to TypeScript tool or JSON to Zod generator to produce type-safe definitions in seconds.
Interactive Tools for JSON (JavaScript Object Notation)
Free, browser-based utilities to test, generate, and inspect JSON (JavaScript Object Notation) payloads directly.
JSON Formatter
text-dataPrettify, minify, and validate JSON data instantly.
JSON to C# Class
developer-toolsConvert JSON to C# classes with System.Text.Json or Newtonsoft serialization.
JSON to Go Struct
developer-toolsConvert JSON to Go structs with json tags and idiomatic naming.
JSON to Rust Struct
developer-toolsConvert JSON into idiomatic Rust structs with Serde Serialize and Deserialize derive macros.
JSON to Dart
developer-toolsConvert JSON to null-safe Dart classes with json_serializable & fromJson constructors.
JSON to TypeScript
developer-toolsConvert JSON to TypeScript interfaces or type aliases instantly.
JSON to TypeScript & Schema Generator
developer-toolsGenerate TypeScript interfaces, Zod schemas, and Valibot schemas from JSON.
JSON to Zod Schema
developer-toolsConvert JSON to Zod schema definitions with automatic TypeScript type inference.
JSON Repair Tool
text-dataRepair and fix malformed JSON data from AI outputs, API responses, and copy-paste.
JSON Path Tester
developer-toolsQuery and extract data from JSON documents using JSONPath.