JSON and Algebraic Data Types
Written by Eric Normand. Published: August 17, 2012.
Eric Normand’s Newsletter
Software design, functional programming, and software engineering practices
Over 5,000 subscribers
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:
- Null
- Boolean
- Number
- String
- List
- 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?
Sean Allen
Your friendly reminder that if you aren’t reading Eric’s newsletter, you are missing out…
Your friendly reminder that if you aren’t reading Eric’s newsletter, you are missing out…
Nicolas Hery
Lots of great content in the latest newsletter! Really glad I subscribed. Thanks, Eric, for your work.
Lots of great content in the latest newsletter! Really glad I subscribed. Thanks, Eric, for your work.
Mathieu Gagnon
Eric’s newsletter is so simply great. Love it!
Eric’s newsletter is so simply great. Love it!