Open michielbdejong opened 3 years ago
You probably want to have a @context
that defines what the "name" and "description" terms are. You need that in the source data so it can be expanded. And also as a flatten param if you want the shorter terms in the output.
const jsonld = require('jsonld');
const obj = {
"@context": "http://schema.org/",
"@id": "http://store.example.com/",
"@type": "Store",
"name": "Links Bike Shop",
"description": "The most \"linked\" bike store on earth!"
};
const ctx = {
"@context": "http://schema.org/"
};
jsonld.flatten(obj, ctx).then(x => {
console.log(JSON.stringify(x, null, 2));
});
{
"@context": "http://schema.org/",
"@graph": [
{
"id": "http://store.example.com/",
"type": "Store",
"description": "The most \"linked\" bike store on earth!",
"name": "Links Bike Shop"
}
]
}
Could we use flatten method at frontend environment?
I'm a newby at json-ld but not sure why the following happens when I call
jsonld.flatten
:Run this script:
Expected output:
Actual output: