Publicidad
← Volver

The Complete JSON Guide

Everything you need to know about JSON — format, validation, tools, and best practices.

Publicidad

JSON (JavaScript Object Notation) is a lightweight, text-based data interchange format built on two universal structures: objects (name/value pairs) and arrays (ordered lists). It has become the dominant format for REST APIs, configuration files, and data storage in modern web development.

JSON Syntax Rules

  • Keys must be strings in double quotes
  • No trailing commas after the last item
  • No JavaScript comments (// or /* */)
  • Strings use double quotes only — no single quotes
  • Supported types: string, number, boolean, null, object, array

Working with JSON in JavaScript

// Parse JSON string → JavaScript object
const obj = JSON.parse('{"name":"Alice","age":30}');

// Convert object → JSON string (indent = 2 spaces)
const json = JSON.stringify(obj, null, 2);

// Safe parsing
try {
  const data = JSON.parse(userInput);
} catch (e) {
  console.error('Invalid JSON:', e.message);
}

Common JSON Errors

  • Unexpected token — missing/extra comma, or unquoted key
  • Unexpected end of input — unclosed bracket, brace, or string
  • Invalid character — single quotes or a comment in the JSON

JSON vs XML

JSON is typically 30–40% more compact than equivalent XML, maps directly to JavaScript objects, and is faster to parse. XML remains preferable for documents requiring namespaces, schemas (XSD), or comments.

Frequently Asked Questions

Can JSON have comments?

No. Use JSONC or YAML for configuration files that need comments.

How do I handle dates in JSON?

Use ISO 8601 strings: "2024-01-15T10:30:00Z". JSON has no native date type.

What is NDJSON?

Newline Delimited JSON — one JSON object per line. Ideal for streaming large datasets and log files.

What file size can VisualDevTools handle?

All processing is in your browser. Works well up to 50MB on modern computers — no server upload needed.