What is faster to parse a lot of data (5Mb): eval or json?

I want to get a set of data objects through ajax and analyze them in JS data.

I currently have 2 options: - The server returns a valid javascript code, and then I evaluate it. - The server returns a JSON object and then changes the json object

What is the fastest of them in Firefox? (I only care about the performance of the "parsing", and not about the transfer of the server or data).

+6
json javascript jquery eval ajax
source share
2 answers

See the results that VinylFox came up with when it tested JSON decoding in the wild. Native functions perform best in all browsers.

+7
source share

Firefox 3.5+ has a built-in json parsing function window.JSON.parse - this will probably be the fastest. In older browsers, you might be lucky with (new Function("return "+json))()

+3
source share

All Articles