Hoja de Referencia JSON
Referencia de sintaxis JSON: tipos de datos, caracteres de escape, diferencias JSON5, errores comunes y convenciones de fecha.
Data types
| Type | Example | Notes |
|---|---|---|
| string | "hello" | Double quotes only. UTF-8. |
| number | 42 or 3.14 or -1.2e10 | No NaN, no Infinity. |
| boolean | true or false | Lowercase only. |
| null | null | Lowercase. Means "explicitly absent." |
| object | { "key": "value" } | Keys MUST be double-quoted strings. |
| array | [1, 2, 3] | Ordered list, mixed types allowed. |
Escape sequences inside strings
| Sequence | Character |
|---|---|
\" | Double quote |
\\ | Backslash |
\/ | Forward slash (optional escape) |
\n | Newline |
\r | Carriage return |
\t | Tab |
\b | Backspace |
\f | Form feed |
\uXXXX | Unicode codepoint (4 hex digits) |
Valid vs invalid
✓ Valid
{
"name": "Alice",
"age": 30,
"tags": ["admin", "user"],
"deleted_at": null
}✗ Invalid
{
name: 'Alice', // unquoted key, single quote
age: NaN, // NaN not allowed
tags: ['admin',], // trailing comma
// deleted_at // comment not allowed
}JSON vs JSON5 vs JSONC vs YAML
| Feature | JSON | JSONC | JSON5 | YAML |
|---|---|---|---|---|
| Comments | ❌ | ✅ // and /* */ | ✅ | ✅ # |
| Trailing commas | ❌ | ✅ | ✅ | N/A |
| Unquoted keys | ❌ | ❌ | ✅ | ✅ |
| Single quotes | ❌ | ❌ | ✅ | ✅ |
| Multi-line strings | ❌ | ❌ | ✅ | ✅ |
| Hex / Inf / NaN | ❌ | ❌ | ✅ | Limited |
| Native browser support | ✅ | ❌ | ❌ | ❌ |
| Use case | APIs, storage | VS Code configs | Human-edited configs | CI/CD, K8s |
Date conventions
| Format | Example | Notes |
|---|---|---|
| ISO 8601 (UTC) | "2026-05-06T14:23:45Z" | Standard for APIs. Z = UTC. |
| ISO 8601 (offset) | "2026-05-06T14:23:45+05:30" | With timezone offset. |
| Unix seconds | 1746557025 | Compact, no timezone ambiguity. |
| Unix milliseconds | 1746557025000 | JavaScript Date.now() format. |
Common gotchas
- • JSON.parse(undefined) throws. Always JSON.parse(string), where string is non-undefined.
- • JSON.stringify(undefined) === undefined.
undefinedvalues in objects are silently dropped. - • Numbers lose precision beyond 2^53 (~9 quadrillion). Use string representation for IDs, big integers, or amounts.
- • No circular references — JSON.stringify throws on circular objects. Break the cycle or use a library like flatted.
- • Sorting keys isn't guaranteed — most parsers preserve insertion order, but the spec doesn't require it. Don't rely on key ordering for security or comparison.
- • Date objects become ISO strings in JSON.stringify. To rehydrate, use a reviver:
JSON.parse(s, (k, v) => /^\d{4}-\d{2}-\d{2}/.test(v) ? new Date(v) : v).
Format and validate JSON with our JSON Formatter, or browse JSON visually in the JSON Tree Viewer.
The JSON spec in one paragraph
JSON (JavaScript Object Notation) is a text format for structured data. Six data types: string, number, boolean, null, object (key-value pairs), and array (ordered list). Strings use double quotes only. Object keys must be quoted. No comments, no trailing commas, no undefined, no NaN, no Infinity. That's the entire spec.
Use cases & flavor selection
HTTP APIs: strict JSON. VS Code / TypeScript config: JSONC. Configuration files for human editing: JSON5 or YAML. Storage formats: strict JSON or BSON (binary). When in doubt, default to strict JSON — it's the most universally parseable.
Common use cases for this cheat sheet
Backend developers reach for this reference when validating API payloads against the spec, writing test fixtures, or debugging parse errors from third-party integrations. Frontend engineers use it to double-check escape sequence syntax when building dynamic strings. DevOps engineers consult it when authoring JSON-based config files for Terraform, GitHub Actions, or AWS CloudFormation where trailing commas cause silent failures in strict parsers.
Tips for best results with JSON
Always validate JSON with a linter before committing config files — a misplaced comma breaks deployments silently. Use JSON.stringify(obj, null, 2) for human-readable output during debugging. For large payloads, minify before sending over the wire — the difference between pretty-printed and minified can be 30–40% in byte size. Store numeric IDs as strings when they exceed 2^53 to avoid precision loss in JavaScript parsers.
Who uses this JSON cheat sheet
Full-stack developers building REST APIs need to know which types are legal and how to escape edge-case characters in string values. QA engineers writing Postman or Insomnia test suites reference it when crafting request bodies. Data engineers building ETL pipelines use it to understand the difference between strict JSON and JSON5 when their pipeline tools diverge on what they accept. Students preparing for coding interviews bookmark it as a concise spec reference that goes deeper than MDN for the tricky corner cases.
Preguntas frecuentes
- What's the difference between JSON, JSON5, and JSONC?
- JSON is the strict spec — no comments, no trailing commas, no unquoted keys, double quotes only. JSONC (JSON with Comments) adds // and /* */ comments — Microsoft uses it for tsconfig.json, .vscode/settings.json. JSON5 is more permissive — adds comments, trailing commas, single quotes, unquoted keys, hex numbers. None of these are interchangeable with strict JSON in production APIs — the API spec dictates which flavor to use.
- Why do trailing commas break JSON?
- Strict JSON forbids trailing commas after the last element of arrays and objects. JavaScript allows them, so developers paste JS-like data and get parse errors. JSON5 and JSONC allow trailing commas. If you need JSON output that other systems will consume, never include them. JSON.stringify() in JavaScript correctly omits trailing commas.
- Can JSON have comments?
- Strict JSON cannot. Comments were intentionally excluded by Douglas Crockford (JSON's creator) to keep the format minimal. If you need comments, use JSON5 or JSONC. As a workaround in strict JSON, some teams use a special key like '_comment' to embed notes — though this clutters the data.
- How do I represent dates in JSON?
- Use ISO 8601 strings: '2026-05-06T14:23:45Z' (UTC) or '2026-05-06T14:23:45+05:30' (with offset). This is the de facto standard in 95% of APIs. Alternatives: Unix timestamps as integers (1746557025) — concise but less human-readable. Avoid local-format strings ('5/6/2026') — they're ambiguous between US and rest-of-world conventions.
- Why are some characters showing as \u00XX in JSON?
- JSON escape sequences. Characters outside ASCII or with special meaning (", \\, /) are escaped as \u followed by 4 hex digits. JSON.stringify() escapes these by default for safety. To get human-readable Unicode, parse and re-stringify in your application code, or use JSON.stringify(obj, null, 2) which preserves Unicode in modern engines.
Herramientas relacionadas
- Formateador JSON con Validación y Reparación
Formatea, minifica, valida y repara JSON al instante en tu navegador. Ordena claves alfabéticamente, formato automático al pegar, descarga como archivo — gratis, sin registro, 100% en el cliente.
- Generador de Código QR
Genera códigos QR para URLs, texto, Wi-Fi y más. Descarga como PNG.
- Generador de Contraseñas
Genera contraseñas fuertes y aleatorias con longitud y conjuntos de caracteres personalizados.
- Codificador / Decodificador Base64
Codifica texto a Base64 o decodifica Base64 de vuelta a texto plano.
- Codificador / Decodificador de URL
Codifica o decodifica URLs y cadenas de consulta con codificación por porcentaje.