Skip to content

Instantly share code, notes, and snippets.

@jeffhandley
Created December 10, 2013 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffhandley/7883875 to your computer and use it in GitHub Desktop.
Save jeffhandley/7883875 to your computer and use it in GitHub Desktop.
Named objects in a graph
// What Example 46 shows here: http://json-ld.org/spec/latest/json-ld
"@graph" : [
{
"@id": "#homer",
"http://example.com/vocab#name": "Homer"
},
{
"@id": "#bart",
"http://example.com/vocab#name": "Bart",
"http://example.com/vocab#parent": { "@id": "#homer" }
},
{
"@id": "#lisa",
"http://example.com/vocab#name": "Lisa",
"http://example.com/vocab#parent": { "@id": "#homer" }
}
]
// What we want
"@graph" : {
"#homer" : {
"http://example.com/vocab#name": "Homer"
},
"#bart" : {
"http://example.com/vocab#name": "Bart",
"http://example.com/vocab#parent": { "@id": "#homer" }
},
"#lisa" : {
"http://example.com/vocab#name": "Lisa",
"http://example.com/vocab#parent": { "@id": "#homer" }
}
}
@msporny
Copy link

msporny commented Dec 10, 2013

You can achieve something like that through JSON-LD's Data Indexing feature: http://www.w3.org/TR/json-ld/#data-indexing

Note, you will lose the @id if you don't "repeat" it in the object... also, you probably don't need @graph there.

@jeffhandley
Copy link
Author

We were looking at the indexing feature, so we'll look into that more; thanks!

And good to know about @graph being unnecessary here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment