JSON and ES4
5 November 2007To say that ES4 is a hot topic is probably quite an understatement. Controversy over the proposed successor to ES3/JavaScript 1 has been intense. I don’t want to get into the general arguments about ES4, however, there are a number of aspects of ES4 that may affect JSON that I wanted to take a look at.
- toJSONString(), parseJSON() - ES4 proposes to add toJSONString as a method on all objects, and parseJSON as a method on all strings. These method will provide native support for serialization and deserialization of JSON data. This approach has met with some resistance. With Douglas Crockford’s recent change in his advised API for JSON, this approach may lose some of it’s forward compatibility as well.
- Namespaces - ES4 has introduced the concept of namespaces. Any property on a object may have a namespace in addition to the string identifier. For example:
namespace myNameSpace.
obj={foo:"bar"};
obj.myNameSpace::foo = "another value";
The “obj” object now has two properties with the name of “foo”, but with different namespaces. This presents some issues for serialization of objects to JSON. How should namespaced properties be represented in JSON? This appears to still be an open question for the ES4 working group. The current reference implementation simply fails when it encounters a namespaced property. - ES4 will also add more objects and mechanisms that will not be JSON serializable as well.
Now, I believe that ES4 is a great language, and I am excited to use it, but I just thought it would be interesting to examine how it will impact JSON usage in JavaScript.
No comments yet