Mayukh Roy Mayukh Roy - 2 months ago 14
JSON Question

JSON parsing in javascript for json-ld

Trying to parse a JSON from json-ld

Here is the JSON below:

{
"@context": "http://json-ld.org/contexts/person.jsonld",
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
}


So I am trying to do this:

var jsonData= {
"@context": "http://json-ld.org/contexts/person.jsonld",
"@id": "http://dbpedia.org/resource/John_Lennon",
"name": "John Lennon",
"born": "1940-10-09",
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
};

console.log(jsonData.@context);// Error:Uncaught SyntaxError: Invalid or unexpected token
console.log(jsonData.name);// John Lenon


How do i parse the @context then? Please suggest.

Answer
console.log(jsonData['@context']);

More about Javascript Property accessors: dot notation and bracket notation.