Parsing JSON - J Query

You’re passed a string of JSON data and need to convert it to object format.


As discussed in the previous recipe, we’ll now look at parsing or decoding a JSON string. The easiest approach in consuming JSON data is to eval() the message. There are some inherent security issues though with this approach because eval() encompasses the entire JavaScript specification instead of simply the JSON subset. What this means is that a malicious person could execute code embedded in the JSON string. So, we don’t recommend this approach. Instead, let’s use Douglas Crockford’sJSON library mentioned in the previous recipe. (Note that his library does utilize eval() except that it pre-processes the data to make sure the data is safe.)

So, now we can work with our message object as we would any other JavaScript object:

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

J Query Topics