Quantcast
Channel: Question and Answer » json
Viewing all articles
Browse latest Browse all 148

Anything wrong with direct evaluation of JSON if your own code created it?

$
0
0

Suppose I have a server-side variable containing JSON (named strJSON) that my own code created. In JavaScript I can consume it like this:

var data = <%= strJSON %>;

or use a JSON parsing library:

var data = JSON.parse('<%= HttpUtility.JavaScriptStringEncode(strJSON) %>');

I prefer the 2nd, for safety. Is what I’m doing unnecessary?


Viewing all articles
Browse latest Browse all 148

Trending Articles