JSON to JSON-LD without changing source

There are "duplicates" in my question, but they don't answer my question.

Considering the following JSON-LD example as described in 6.13 - Named Graphics from http://www.w3.org/TR/json-ld/ :

{
    "@context": {
    "generatedAt": {
    "@id": "http://www.w3.org/ns/prov#generatedAtTime",
    "@type": "http://www.w3.org/2001/XMLSchema#date"
    },
    "Person": "http://xmlns.com/foaf/0.1/Person",
    "name": "http://xmlns.com/foaf/0.1/name",
    "knows": "http://xmlns.com/foaf/0.1/knows"
    },
    "@id": "http://example.org/graphs/73",
    "generatedAt": "2012-04-09",
    "@graph":
             [
                  {
                   "@id": "http://manu.sporny.org/about#manu",
                   "@type": "Person",
                   "name": "Manu Sporny",
                   "knows": "http://greggkellogg.net/foaf#me"
                   },
                   {
                   "@id": "http://greggkellogg.net/foaf#me",
                   "@type": "Person",
                   "name": "Gregg Kellogg",
                   "knows": "http://manu.sporny.org/about#manu"
                   }
             ]
}

      

Question:

What if you start with a JSON piece without a semantic layer:

[{
  "name": "Manu Sporny",
  "knows": "http://greggkellogg.net/foaf#me"
},
{
  "name": "Gregg Kellogg",
  "knows": "http://manu.sporny.org/about#manu"
}]

      

and you link @context to a separate file or location using the http link header or rdflib parsing, then you are left without @id and @type in the rest of the document. Including these missing key values ​​in the json string is not a clean option. The idea is to go from JSON to JSON-LD without changing the original JSON part.

As I can see, to define a three-local object one has to use @id to match the IRI. It is highly unlikely that JSON data has @id key values. Does this mean that all JSON files cannot be parsed as JSON-LD without adding keys in the first place? I wonder how they do it. Anyone have an idea to point me in the right direction? Thank.

+3


source to share


1 answer


No, unfortunately this is not possible. There are, however, libraries and tools created for this very reason. JSON-LD Macros is such a library. It allows declarative transformations of JSON objects to make them usable as JSON-LD. Thus, all you need is a very thin layer on top of the JSON-LD processor out of the box.



+4


source







All Articles