Search code examples
javascriptjsonprotovis

Assign json stored in a file to a js variable


I am working on a project and I was not able to figure out how to do this. I have a json file and need to assign it to a js variable to use the protovis visualization tools.

I tried searching on google but could not find any. Please let me know if someone knew how to do this. Thanks!


Solution

  • Use jQuery's parseJSON().

    Description: Takes a well-formed JSON string and returns the resulting JavaScript object. version added: 1.4.1jQuery.parseJSON( json ) jsonThe JSON string to parse. Passing in a malformed JSON string may result in an exception being thrown.