Lección 6

JSON in APIs and Configs en español

Guía en español para json json in apis and configs: REST payloads, config files, and JSON compared to XML and YAML.

Este contenido todavía no está disponible en español. Se muestra la versión en English mientras completamos la localización.

Understanding JSON in context helps you choose formats wisely and read documentation more effectively.

REST APIs

HTTP APIs often use JSON for bodies and sometimes query-less POST payloads:

POST /users HTTP/1.1
Content-Type: application/json

{"name": "Ada", "role": "admin"}

Responses mirror the same format. Status codes live in HTTP headers; JSON carries the business data. Schemas may be documented with OpenAPI, JSON Schema, or prose examples.

Configuration files

Tools like package.json, tsconfig.json, and many CI configs are JSON. Benefits:

  • Easy for programs to parse
  • Widely supported in editors
  • Diff-friendly in version control when formatted

Trade-off: no comments in strict JSON (some tools accept JSONC—a superset with comments—but portable configs stick to standard JSON).

JSON vs XML

JSONXML
VerbosityUsually shorterOften more tags
TypesMinimal (string, number, …)Attributes + text nodes
SchemaJSON Schema, OpenAPIXSD, DTD
Typical use todayWeb APIsLegacy enterprise, documents

JSON vs YAML

YAML is human-friendly for configs and supports comments. It is common in Kubernetes and Docker Compose files. Pitfalls: indentation-sensitive, harder to parse securely at scale. JSON is stricter and safer for untrusted input; YAML is often chosen when humans edit large configs by hand.

Security note

Never eval() JSON text—parse with a dedicated library. For untrusted payloads, validate against a schema and limit size to reduce denial-of-service risk.

Course summary

You now have a foundation in JSON syntax, types, structure, common errors, and real-world usage. Apply this when reading API docs, designing payloads, or reviewing config changes in pull requests.

Volver al resumen del curso