Death of ECMA 4 and future of Native JSON parsing



JSON is a subset of JavaScript.It is used to represent data as tokens of name - value pairs.This technology provides an efficient dataportability for mashable appliations.The JSON syntax is like JavaScript's object literal syntax except that the objects cannot be assigned to a variable. JSON just represents the data itself.Data is the string.This literal has to be converted to object.We can use eval() in Javascript to evaluate script.But using eval() is harmful.So a JSON parser will recognize only JSON text, rejecting all scripts.




If u need a javascript parser use ..

JSON.parse(strJSON) - converts a JSON string into a JavaScript object.
JSON.stringify(objJSON) - converts a JavaScript object into a JSON string.
Other parsers are

Jackson JSON Processor based on , STreaming Api for Xml processing .

JSON-lib is a java library for transforming beans, maps, collections, java arrays and XML to JSON and back again to beans and DynaBeans.

If you are using mozilla firefox and your browser supported above gecko 1.9, there is a regexp:test() function.

According to specification proposed by D.Crockford :

A JSON text can be safely passed into JavaScript's eval() function (which compiles and executes a string) if all the characters not enclosed in strings are in the set of characters that form JSON tokens. This can be quickly determined in JavaScript with two regular expressions and calls to the test and replace methods.

var my_JSON_object = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
eval('(' + text + ')');


This particular technology is alternative to XML to port data.The webservices implementations return XML data.The applications use parsers to generate native objects from these XML.XML is the data used in AJAX, which became the buzz in new age web.The data format is vital to the efficiency of any application.JSON provides an efficient data transfer.

Read JSON: The Fat-Free Alternative to XML

If you want to add JSON to application , read here how Yahoo webservices implemented this.

According to John Resig, browsers should support native json support,

He summarises that

The current, recommended, implementation of JSON parsing and serialization is harmful and slow. Additionally, upcoming standards imply that a native JSON (de-)serializer already exists. Therefore, browsers should be seriously looking at defining a standard for native JSON support, and upon completion implement it quickly and broadly.
Read here for the ECMA4 proposal

but now ?

ECMAScript 4.0 Is Dead


JavaScript standards wrangle swings Microsoft's way

The industry is again having war on browsers and internet standards.

So different methodologies to make JSON will be exist for some years on.As the system become complex, vulnerabilites will arise and we have to findout resolutions for those issues every time.

No comments:

Post a Comment