There are many things wrong here
Your JSON is invalid
You have an extra ,
just before the end of the array that you need to remove
You need to parse
JSON.stringify
converts a JavaScript data structure into a string of JSON.
You need to go the other way and use JSON.parse
.
Square-bracket notation takes strings
mylovelyJSON[id]
takes the value of id
(which is undeclared so, in this case, would throw a reference error) and gets the property with the name that is the same as that value.
You need either mylovelyJSON["id"]
or mylovelyJSON.id
You have an array
Your JSON consists of an array of objects, not a single object.
You need to get an object out of the array before you can access properties on it.
mylovelyJSON[0]["id"]
var json_text = '[{"id":"001","name":"Charlie"},{"id":"002","name":"Ellie"}]';
parseJSON(json_text);
function parseJSON(string){
var result_of_parsing_json = JSON.parse(string);
document.body.appendChild(
document.createTextNode(result_of_parsing_json[0]["id"])
);
}