JSON and Algebraic Data Types

August 16, 2012

I recently wrote about the birth of JSON, which describes how JSON came to be and the story of its success. Crawford talks about how JSON (or a very close equivalent) was reinvented several times throughout the years.

What strikes me is that JSON turned out to be an Algrebraic Data Type (ADT). Specifically, it is a tagged union.

JSON ADT variants:

  1. Null
  2. Boolean
  3. Number
  4. String
  5. List
  6. Dictionary

With these six constructors, you can make all of JSON.

It's interesting because JSON is a point of intersection between Javascript and Haskell. Javascript is very dynamic, with a very weak sense of type. Haskell has strong typing. On close analysis, JSON is statically and strongly typed. In fact, JSON is a type.

Could its ADT nature be one of the secrets to JSON's success?