Site Logotype, floated left.
SM0TVI Namespace: File Information Schemas

RDF/JSON

CC-BY-SA
This work is licensed under the Creative Commons Attribution-ShareAlike License 4.0.

Media Type:
application/rdf+json.
Extension(s):
.rj.
Parameters: N/A.
Information symbol
Deprecated

The syntax described in this document is an alternative to JSON-LD. It SHOULD NOT be used unless there is a specific reason to do so. Use of JSON-LD is RECOMMENDED.

Algorithm

Deserialization

Given a RDF/JSON document, a set of RDF Triples may be constructed using the following algorithm:

  1. Create an empty output buffer.
  2. For each property in the object:
    1. Check whether the property value is an object.
    2. Let the property name (key) be the subject URI S
    3. For each property in the property value object:
      1. Check whether the property value is an array.
      2. Let the property name (key) be the predicate URI P
      3. For each value in the array:
        1. Check the value of the type property.
          • if the value is the string “uri
          • if the value is the string “bnode
          • if the value is the string “literal
            • if the object has a “lang” property
            • if the object has a “datatype” property
        2. Add the the triple [ S, P, O ] to the output buffer.

Serialisation

Given a set of RDF Triples a RDF/JSON document may be constructed using the following algorithm:

  1. Start a JSON object (called the root object)
  2. Group all the triples by subject
  3. For each unique subject:
    1. Create a JSON object for the subject (called the subject object)
    2. Group all triples having the current subject by predicate
    3. For each unique predicate:
      1. Create a JSON array (called the value array)
      2. Select all triples having the current subject and current predicate
      3. For each triple:
        1. Create a JSON object (called the value object)
        2. Add the following key/value pairs to the value object:
          • If the object of the triple is an RDF URI Reference U add a key called “type” with a value being the string “uri”. Add a key called “value” with the value being U.
          • If the object of the triple is an RDF Literal S add a key called “type” with a value being the string “literal”. Add a key called “value” with the value being the lexical form of S and:
            • If the object of the triple is an RDF Literal with language L, add a key called “lang” with the value being L.
            • If the object of the triple is an RDF Typed Literal with datatype URI D, add a key called “datatype” with the value being D.
          • If the object of the triple is a Blank Node with label I add a key called “type” with a value being the string “bnode”. Add a key called “value” with the value being the string formed by concatenting an underscore (U+005F) followed by a colon (U+003A) followed by I.
        3. Push the value object onto the end of the value array.
      4. Add a key/value pair to the subject object with the key being the predicate URI and the value being the value array.
    4. Add a key/value pair to the root object with value being the subject object created in the previous step and the key being one of the following:
      • If the subject of the triple is an RDF URI Reference U the key is U.
      • If the subject of the triple is a Blank Node with label I the key is the string formed by concatenting an underscore (U+005F) followed by a colon (U+003A) followed by I.

Examples

The following RDF/XML:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:foaf="http://xmlns.com/foaf/0.1/"
  xmlns:dc="http://purl.org/dc/elements/1.1/">
  <rdf:Description rdf:about="http://example.org/about">
    <dc:creator>Anna Wilder</dc:creator>
    <dc:title xml:lang="en">Anna's Homepage</dc:title>
    <foaf:maker rdf:nodeID="person" />
  </rdf:Description>
  <rdf:Description rdf:nodeID="person">
    <foaf:homepage rdf:resource="http://example.org/about" />
    <foaf:made rdf:resource="http://example.org/about" />
    <foaf:name>Anna Wilder</foaf:name>
    <foaf:firstName>Anna</foaf:firstName>
    <foaf:surname>Wilder</foaf:surname>
    <foaf:depiction rdf:resource="http://example.org/pic.jpg" />
    <foaf:nick>wildling</foaf:nick>
    <foaf:nick>wilda</foaf:nick>
    <foaf:mbox_sha1sum>69e31bbcf58d432950127593e292a55975bc66fd</foaf:mbox_sha1sum>
  </rdf:Description>
</rdf:RDF>

Can be represented as the following RDF/JSON structure:

{ 
  "http://example.org/about" : { 
      "http://purl.org/dc/elements/1.1/creator" : [ { 
            "type" : "literal",
            "value" : "Anna Wilder"
          } ],
      "http://purl.org/dc/elements/1.1/title" : [ { 
            "lang" : "en",
            "type" : "literal",
            "value" : "Anna's Homepage"
          } ],
      "http://xmlns.com/foaf/0.1/maker" : [ { 
            "type" : "bnode",
            "value" : "_:person"
          } ]
    },
  "_:person" : { 
      "http://xmlns.com/foaf/0.1/depiction" : [ { 
            "type" : "uri",
            "value" : "http://example.org/pic.jpg"
          } ],
      "http://xmlns.com/foaf/0.1/firstName" : [ { 
            "type" : "literal",
            "value" : "Anna"
          } ],
      "http://xmlns.com/foaf/0.1/homepage" : [ { 
            "type" : "uri",
            "value" : "http://example.org/about"
          } ],
      "http://xmlns.com/foaf/0.1/made" : [ { 
            "type" : "uri",
            "value" : "http://example.org/about"
          } ],
      "http://xmlns.com/foaf/0.1/mbox_sha1sum" : [ { 
            "type" : "literal",
            "value" : "69e31bbcf58d432950127593e292a55975bc66fd"
          } ],
      "http://xmlns.com/foaf/0.1/name" : [ { 
            "type" : "literal",
            "value" : "Anna Wilder"
          } ],
      "http://xmlns.com/foaf/0.1/nick" : [ 
          { 
            "type" : "literal",
            "value" : "wildling"
          },
          { 
            "type" : "literal",
            "value" : "wilda"
          }
        ],
      "http://xmlns.com/foaf/0.1/surname" : [ { 
            "type" : "literal",
            "value" : "Wilder"
          } ]
    }
}

References and Further Reading