JTriples

From W3C Wiki
Jump to: navigation, search

Note: this is yet another proposal for RDF-in-JSON, see JSON+RDF for a comprehensive list on the proposals on the table.

As drewp pointed out on #swig IRC channel the other day ... I'm surprised someone hasn't done the "ntriples of json formats"- some super-simple thing with just a list of 3-arrays - well here I am and give it a try. Not that I think its super-useful or will really enjoy any take-up, but alas one should have a look at all available options before making a decision what to support ;)

Starting point: NTriples

The definition of NTriples can be found in the RDF Test Cases, where it says:

N-Triples is a line-based, plain text format for encoding an RDF graph.

A simple way to express RDF triples in JSON - JTriples

Basics

The example from sec 3.4 of the RDF Test Cases, which looks in NTriples as follows:

<http://www.w3.org/2001/08/rdf-test/>  <http://purl.org/dc/elements/1.1/creator>    "Dave Beckett" .
<http://www.w3.org/2001/08/rdf-test/>  <http://purl.org/dc/elements/1.1/creator>    "Jan Grant" .
<http://www.w3.org/2001/08/rdf-test/>  <http://purl.org/dc/elements/1.1/publisher>  _:a .
_:a                                    <http://purl.org/dc/elements/1.1/title>      "World Wide Web Consortium" .
_:a                                    <http://purl.org/dc/elements/1.1/source>     <http://www.w3.org/> .

would look in JTriples something like:

[
 {
  "s": "<http://www.w3.org/2001/08/rdf-test/>",
  "p": "<http://purl.org/dc/elements/1.1/creator>",
  "o": "Dave Beckett"
 },
 {
  "s": "<http://www.w3.org/2001/08/rdf-test/>",
  "p": "<http://purl.org/dc/elements/1.1/creator>",
  "o": "Jan Grant"
 },
 {
  "s": "<http://www.w3.org/2001/08/rdf-test/>",
  "p": "<http://purl.org/dc/elements/1.1/publisher>",
  "o": "_:a"
 },
 {
  "s": "_:a",
  "p": "<http://purl.org/dc/elements/1.1/title>",
  "o": "World Wide Web Consortium"
 },
 {
  "s": "_:a",
  "p": "<http://purl.org/dc/elements/1.1/source>",
  "o": "<http://www.w3.org/>"
 }
]

One would expect that the relevant bits from the NTriples specifications from sec 3.2 Strings and sec 3.3 URI References are applicable to JTriples as well.

Handling Literals

Language specification in literals are expressed inline and should not require additional sub-structures. That is, for example, the following NTriples statement:

<http://example.org> <http://purl.org/dc/terms/title> "Example Title"@en .

in JTriples is:

[
 {
  "s": "<http://example.org>",
  "p": "<http://purl.org/dc/terms/title>",
  "o": "\"Example Title\"@en"
 }
]

Typed literals follow the same pattern as language tags, above. Hence, an NTriples statement such as:

<http://example.org> <http://purl.org/dc/terms/date> "2010-12-02"^^<http://www.w3.org/2001/XMLSchema#date> .

would be represented in JTriples as:

[
 {
  "s": "<http://example.org>",
  "p": "<http://purl.org/dc/terms/date>",
  "o": "\"2010-12-02\"^^<http://www.w3.org/2001/XMLSchema#date>"
 }
]