Skip to main content
Glossary

JSON

JavaScript Object Notation. A lightweight, text-based data interchange format that is easy for humans to read and write and easy for machines to parse and generate.

Detailed Explanation

JSON is the de facto standard for data exchange on the web. It uses key-value pairs (objects) and ordered lists (arrays) to represent data. JSON is language-independent despite its JavaScript syntax—every modern programming language has JSON parsing libraries.

JSON is used in APIs (request/response bodies), configuration files (package.json, tsconfig.json), data storage (MongoDB documents), and inter-service communication. It replaced XML as the dominant data format because it is simpler, smaller, and easier to work with. JSON supports strings, numbers, booleans, null, objects, and arrays—covering most data representation needs.

Why It Matters

JSON is the universal data format of the web. Every developer must understand it, and virtually every API uses it.

Real-World Example

A weather API returns: `{"city": "New York", "temp": 72, "conditions": "sunny", "forecast": [{"day": "Mon", "high": 75}]}`. The client parses this JSON and displays the weather data.

When to Use

For API request/response bodies, configuration files, data storage (document databases), and any text-based data exchange. JSON is the default choice for most data interchange.

Advantages

  • Human-readable and writable
  • Language-independent
  • Compact compared to XML
  • Native JavaScript support
  • Extensive library support in all languages

Disadvantages

  • No built-in date type (use ISO strings)
  • No comments allowed in standard JSON
  • Less expressive than XML for complex documents
  • No schema validation built-in (use JSON Schema)
  • Can be larger than binary formats (Protocol Buffers, MessagePack)

Frequently Asked Questions

What is the difference between JSON and XML?

JSON is simpler, smaller, and easier to parse. XML supports attributes, namespaces, and schemas. JSON has largely replaced XML for web APIs. XML is still used in enterprise systems (SOAP) and document formats (XHTML).

How do I handle dates in JSON?

JSON has no date type. Use ISO 8601 strings ("2024-01-15T10:30:00Z"). Most languages have libraries to parse ISO dates. Avoid Unix timestamps for API responses—they are harder to read and debug.

What is JSON Schema?

JSON Schema is a vocabulary for validating JSON data. It defines the expected structure, types, and constraints of JSON documents. It is like XSD for XML but designed for JSON. Use it for API request/response validation.

Is JSON better than YAML?

JSON is more widely supported and stricter (no ambiguity). YAML is more human-readable (indentation-based, supports comments). JSON is better for APIs and data exchange. YAML is better for configuration files.

Can JSON handle binary data?

Not directly. Base64-encode binary data to store it in JSON. For large binary payloads, consider multipart form data or separate binary endpoints. Protocol Buffers or MessagePack are better for binary-heavy data.

Back to Glossary

Browse all terms in our software development glossary.

Browse All Terms