4

Am a newbie in json/javascript so please bear with me. Am getting json data from an api url that loads sth like

 {
"employees": [
{ "firstName":"John" , "lastName":"Doe" }, 
{ "firstName":"Anna" , "lastName":"Smith" }, 
{ "firstName":"Peter" , "lastName":"Jones" }
]

i need it as a javascript variable on a script file

var employess={
"employees": [
{ "firstName":"John" , "lastName":"Doe" }, 
{ "firstName":"Anna" , "lastName":"Smith" }, 
{ "firstName":"Peter" , "lastName":"Jones" }
]
}

Ave tried

$.getJSON(myUrl",function(data){ $("#selector").data("JSONP",data); alert(data); });
2

1 Answer 1

3

Put your JSON string a variable var jsonString

then...

var myJsonObject = JSON.parse(jsonString);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.