RDF Logotype,
floated right.
Site Logotype, floated left.
RDF/JSON
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
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:
- Create an empty output buffer.
- For each property in the object:
- Check whether the property value is an object.
- Let the property name (key) be the subject URI S
- For each property in the property value object:
- Check whether the property value is an array.
- Let the property name (key) be the predicate URI P
- For each value in the array:
- 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
- if the object has a
“
- if the value is the string
“
- Add the the triple [ S, P, O ] to the output buffer.
- Check the value of the
Serialisation
Given a set of RDF Triples a RDF/JSON document may be constructed using the following algorithm:
- Start a JSON object (called the root object)
- Group all the triples by subject
- For each unique subject:
- Create a JSON object for the subject (called the subject object)
- Group all triples having the current subject by predicate
- For each unique predicate:
- Create a JSON array (called the value array)
- Select all triples having the current subject and current predicate
- For each triple:
- Create a JSON object (called the value object)
- 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 an
RDF
Literal with language L, add a key
called “
- 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.
- If the object of the triple is an RDF
URI Reference
U add a key called
“
- Push the value object onto the end of the value array.
- Add a key/value pair to the subject object with the key being the predicate URI and the value being the value array.
- 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
-
Ian Davis
(ed.), Thomas Steiner (ed.), Arnaud J Le
Hors (ed.):
RDF 1.1 JSON Alternate Serialization
(RDF/JSON). World Wide Web
Consortium (W3C).
This is the informal RDF/JSON recommendation.
-
RDF
JSON. Talis.
N.B.: Original website is extinct, backup copies available at The Wayback Machine and locally at
<20140313-talis.com-spec.html>
.