3

I have a problem to construct IRI for the object using a prefix and a data value when converting non-edited JSON data into JSON-LD. The example code I have running is:

{ 
    "@context" : 
    { "prefix" : "http://www.gerastree.at/",
      "rdfs" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
      "@vocab" : "http://example.com/" ,
      "load" : "prefix:load"
       "items" : "prefix:item"

    }, 
    "@type" : "tree",
    "@id" : "prefix:t1" , 
    "items" : 
    [
        { "@id" : "prefix:t2",
          "@type" : "item",
          "load" : "some111"
         },
        { "@id" : "prefix:t3",
          "@type" : "item",
          "load" : "some2222"
         }    
    ]
}

but when I change the @id values from "prefix:t1" to the plain data values I have in the original JSON (i.e. to just "t1", "t2" and "t3") the objects are not dealt with anymore. The code which is not proper JSON-LD (at least not read by riot)

{ 
    "@context" : 
    { "prefix" : "http://www.gerastree.at/",
      "rdfs" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
       "@vocab" : "http://example.com/" ,
       "load" : "prefix:load"
       "items" : "prefix:item"

    }, 
    "@type" : "tree",
    "@id" : "t1" , 
    "items" : 
    [
        { "@id" : "t2",
          "@type" : "item",
          "load" : "some111"
         },
        { "@id" : "t3",
          "@type" : "item",
          "load" : "some2222"
         }    
    ]
}

The value "t1" etc. are unique and I would like to use them with a prefix as IRI to link the data with other data. Is there a way to produce the IRI with some addition to the context without changing the program which produces the JSON data or edit the file.

I found a solution (based on the solution of Json-LD > Define a "person" for easy reuse as values on different keys for WebPage schema) but do not understand why it works.

{ 
    "@context" : 
    { "prefix" : "http://www.gerastree.at/",
      "rdfs" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
       "@base" : "http://example.com/" ,
      "load" : "prefix:load",
     "items" : "prefix:item"

    }, 
    "@type" : "tree",
    "@id" : "t1" , 
    "items" : 
    [
        { "@id" : "t2",
          "@type" : "item",
          "load" : "some111"
         },
        { "@id" : "t3",
          "@type" : "item",
          "load" : "some2222"
         }    
    ]
}

I do not think this is a duplicate of Any way to specify the default URI for the @id of a @type or the values of a property? .

What additions and changes to the context are necesary?

1 Answer 1

1

I found the explanation why my third version works as desired with some more reading of the JSON-LD recommendations and experimentation.

@vocab is applied to properties and objects only @base is used to complete IRI for the subject.

not really obvious but flexible enough for my application.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.