Skip to content
Back to blog

JSON Toolbox: Why JSON Fit Web APIs So Well

5 min read
JSON Toolbox: Why JSON Fit Web APIs So Well

JSON is often described as the format that defeated XML by removing closing tags. That account fits neatly into one paragraph but does not explain the history very well. XML was designed primarily as general-purpose markup for documents and structured information exchange, while JSON grew out of the practical need to move application state between a browser and a server. JSON was indeed a better fit for many simple web APIs, but that does not make XML a mistake or mean the two formats model every problem in the same way.

Why XML was created

By the mid-1990s, HTML had shown the value of delivering documents over a network, but its fixed vocabulary was not enough for publishing, scientific, and industry-specific systems. SGML allowed communities to define their own markup languages, although it was too complex for broad use on the web. A W3C working group retained its central ideas in a smaller set of rules, which became the XML 1.0 Recommendation on February 10, 1998.

XML let authors define elements appropriate to their subject and preserve document structure rather than only a tree of application values. A paragraph could interleave ordinary text with emphasis, links, and formulas without turning the content into an artificial set of fields. Attributes described element properties, child order was retained, and comments and processing instructions were part of the syntax.

Simple XML did not require the whole family of related standards. Namespaces became necessary when a document combined vocabularies and applications needed to distinguish elements with the same local name; W3C standardized that mechanism in January 1999. XSLT addressed the separate task of transforming an XML tree into another document, while XML Schema, released in 2001, described permitted structures, constraints, and types such as dates or integers. These technologies made the ecosystem larger, but they were created for vocabulary reuse, document validation, and complex automated exchange rather than for formatting one small object.

The cost of that generality is visible even in a small example:

<person>
  <name>Alex</name>
  <age>30</age>
</person>

Without XML Schema, a parser sees the content of age as text. In return, the same model can add attributes, mixed content, and elements from other namespaces without changing formats. That is valuable for documents but often broader than an application object needs.

How JSON emerged

In 2001, Douglas Crockford and Chip Morningstar were building a State Software platform for what would now be called single-page applications. The browser needed to exchange small pieces of state with a server without replacing the entire page, so the team wanted a representation that could be generated easily on the server and turned into values in JavaScript.

The suitable notation was already present in the language. Object and array literals expressed the same structures the application used. Crockford later stressed that he did not consider himself the first inventor of the technique because several developers had discovered it independently. His contribution was to apply the model at State Software in spring 2001, give it the name JavaScript Object Notation, acquire json.org in 2002, and publish a description of the format. Morningstar helped design the server system and the original data-exchange problem, while Crockford wrote the specification and later RFC.

The same simple record was compact and preserved the distinction between a string and a number:

{
  "name": "Alex",
  "age": 30
}

JSON used familiar JavaScript conventions but was not an arbitrary object literal. Member names require double quotes, and comments, functions, undefined, single-quoted strings, and trailing commas are outside its grammar. Restricting the language was useful for data exchange because a receiver did not need to execute a general-purpose programming language.

Standardization followed real-world use

In July 2006, RFC 4627 registered the application/json media type and formally described syntax that deployed systems already used. Douglas Crockford was the document's sole author. That first RFC allowed only an object or array at the top level; later specifications accepted any JSON value and clarified interoperability requirements.

The current main IETF document is RFC 8259, dated December 2017 and aligned with ECMA-404. It defines JSON as a language-independent text format and requires UTF-8 for exchange between systems. RFC 4627 remains an important standardization milestone, but it is no longer the final modern definition.

Early browser applications sometimes parsed a response with eval() because valid JSON closely resembled a JavaScript expression. The convenience carried a serious risk: eval() executes code with the page's privileges, so an untrusted response could become an XSS vulnerability. ECMAScript 5 added dedicated JSON.parse() and JSON.stringify() methods in December 2009, removing any reason to execute incoming data. Modern code should use a JSON parser, never eval().

Why JSON fit web APIs

JSON's main advantage was not simplicity in the abstract but a close match between data models. Interface state, request parameters, and most API responses map naturally to objects, arrays, strings, numbers, booleans, and null. Similar structures exist as Python dictionaries, PHP arrays, Go maps and structs, Java collections, and equivalents in many other languages, so the format quickly became independent of JavaScript in practice.

For messages of this shape, JSON usually needs less structural syntax than paired XML tags, and its small grammar makes parsers straightforward to implement. There is no universal percentage saving, however. Results depend on the structure, field names, use of XML attributes, and transport compression. Keys also repeat in large homogeneous JSON arrays, while binary formats can be much smaller than either textual option.

Minimalism introduces constraints of its own. JSON does not distinguish integers from fractional numbers, has no native dates or binary values, and does not support mixed document content, namespaces, or references between objects. JSON Schema can describe additional constraints, but it is separate from the base grammar. Implementations can also differ when they encounter duplicate member names or numbers beyond the exact range of a particular language.

XML remains stronger when content is both a document for people and structured input for machines, when several vocabularies must coexist in one file, or when an industry already relies on a rigorous exchange schema. JSON is usually more convenient for object-shaped web application messages and small APIs. The choice follows the shape and requirements of the data, not the outcome of an imaginary format war.

What JSON Toolbox does

JSON Toolbox validates input with the browser's JSON parser as you type. When the engine reports a syntax-error position, the tool converts it to a line and column, marks the corresponding gutter line, and exposes the message in a tooltip.

After a successful parse, the output offers three views: syntax-highlighted Formatted with two spaces, four spaces, or tabs; a collapsible tree with value types; and a one-line Minified representation. The indentation setting is shared with the site's other formatting tools. Statistics report key and string counts, the combined number of characters in keys and string values, and byte sizes for the formatted and minified output. You can copy the Formatted or Minified representation, and all parsing happens locally without uploading the pasted data.

For a quick check, paste {"users":[{"id":1,"name":"Alex"},{"id":2,"name":"Maria"}]}, move between Formatted, Tree, and Minified, then remove the comma between two members. The validator will mark the affected line and rebuild all three views as soon as the comma is restored.

Frequently asked questions

Who created JSON?

JSON does not have a single inventor in the usual sense. Developers had transported data with JavaScript literal syntax before 2001; Douglas Crockford independently arrived at the idea at State Software, named the format, and published its description on json.org in 2002. Chip Morningstar worked with him on the system that needed this form of data exchange.

Why did JSON become popular for web APIs?

Its model of objects, arrays, and primitive values matched application data well, while its small syntax made messages easy to produce and parse. Adoption was also helped by JavaScript in the browser, standard JSON.parse and JSON.stringify methods, and later by built-in libraries across other languages.

Is JSON only for JavaScript?

No. The current specification defines JSON as a language-independent text format. Its syntax was derived from ECMAScript, but parsers and serializers exist in virtually every widely used language. Not every JavaScript literal is valid JSON either.

Is XML obsolete?

XML remains useful for marked-up documents, mixed text and elements, namespaces, attributes, strict industry vocabularies, schemas, and transformations. SVG, office formats, publishing systems, and many integration standards show that it is a different data model rather than an outdated copy of JSON.

Which types are missing from JSON?

JSON has strings, numbers, objects, arrays, true, false, and null. The base format has no separate date, binary, integer, or decimal types, so applications agree on string representations or use an additional schema. Comments and references between objects are also outside JSON syntax.

Related Articles