JSON is a format for raw data. This is very primitive. It supports dictionaries (aka javascript objects, hashes, associative arrays), arrays, strings, numbers, booleans and zero. It. The reason why this does not do anymore is that these primitives are agnostic for the language, and almost all programming languages โโare built into the tools for processing these data types.
If you had other notations like "class", then suddenly it becomes very attached to specific languages โโor code areas and loses its wide and general applicability.
So think of JSON as simple raw data. JSON is not a sorting of instances or a complete serialization of objects. So yes, you need to write "revivers" if you are going to serialize JS objects created from constructors.
This approach takes things like backbone.js take :
new Book({ title: "One Thousand and One Nights", author: "Scheherazade" });
You simply pass your simple data object (the result of your JSON.parse() ) to your constructor call. From there, you can do any number of things to read the values โโin your new object.
Javascript does not have a standard way to sort all objects, e.g. in ruby โโwith Marhsal.dump(obj) , for example.
EDIT: last important point ...
Javascript objects do not have a โtypeโ as you think of it in other languages. A Javascript object is just a dictionary of key / value pairs. When you do something like new SomeClass() , you get a new object that has a special prototype property that points to the prototype property of an object of the SomeClass function. Wether, an object is an instance of SomeClass , is a less clear question than you might think at first glance.
Instead, you may ask, "What is a constructor function object?" or "What objects are in my prototype chain?"
So, if you want to pass the โtypeโ to JSON, which is stored as a string, then how will you store the reference to the prototype object? Maybe the prototype object is not named at all in the global area and is accessible only through closure? Then, when you write this in a string, you can no longer reference this prototype object.
The fact is that the prototype of javascripts for creating an instance of an object, in combination with its lexical coverage based on closure, and the fact that objects store their values โโmore than C pointers than literal values, it is very difficult to completely serialize the object to a location external to the virtual machine.