Saltar al contenido principal
Z

JSON vs YAML

JSON vs YAML compared — syntax, readability, comments, data types and speed, plus when to use each and free tools to convert between them.

JSON and YAML both describe structured data, and YAML is actually a superset of JSON — every JSON document is valid YAML. The difference is ergonomics: JSON uses explicit braces and brackets and is ubiquitous in APIs, while YAML uses indentation and is favoured for human-edited config files.

JSON vs YAML at a glance

JSON YAML
Syntax Braces {} and brackets [], quoted keys Indentation, minimal punctuation
Comments Not supported Supported with #
Readability Compact, machine-friendly Human-friendly for config
Data types Strings, numbers, bool, null, array, object Same + anchors, references, multi-line strings
Parsing Fast, everywhere Slower, indentation-sensitive
Typical use APIs, web payloads CI/CD, Kubernetes, app config

When to use JSON

Choose JSON for API responses and data interchange — it is faster to parse, supported everywhere, and unambiguous. If a machine reads it, JSON is usually the safer default.

When to use YAML

Choose YAML for files humans edit by hand — CI pipelines, Docker Compose, Kubernetes manifests — where comments and clean indentation matter more than parse speed.

Tools for JSON & YAML

JSON vs YAML

¿Cómo se convierten las fechas y los valores booleanos?

js-yaml sigue el estándar YAML 1.2: las fechas se convierten en cadenas ISO y true/false en valores booleanos. En cambio, "yes"/"no" se mantienen como cadenas de texto (según la especificación 1.2).

¿Qué ocurre con los archivos YAML de varios documentos (separados por ---)?

Solo se convierte el primer documento. Para procesar varios documentos, primero divide la cadena usando `---`.

¿La herramienta admite anchors y aliases en YAML?

Sí: los anchors (&) y los aliases (*) se resuelven durante el parseo, generando los datos duplicados correspondientes en el JSON.