Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 975
Mayukh Roy Avatar asked Dec 18 '22 13:12

Mayukh Roy


1 Answers

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

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

like image 95
WangYudong Avatar answered Dec 27 '22 05:12

WangYudong