I have a json string that is a regular raw string and job a javascript object. How do i load this json into a javascript object so that I can use it normally?
var jsonStr = "{\"property1\": \"test\", \"property2\": \"something else\" }"; alert(loadedJson.property1);
The example above is a basic idea of what I am trying to do. I want to load json from a string and be able to access the properties of this object as if it were a regular javascript object.
1 Answer
To load json from a string, you can use the build in JSON handler in JS. Do this you can call the parse method.
var jsonStr = ""{""property1"": ""test"", ""property2"": ""something else"" }"";
var loadedJson = JSON.parse(jsonStr);
alert(loadedJson.property1);
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String