Skip to content

json2rdf implements a series of straightforward assumptions for serving the content of JSON objects/arrays as RDF triples

License

Notifications You must be signed in to change notification settings

spice-h2020/json2rdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json2rdf

json2rdf implements a series of straightforward assumptions for serving the content of JSON objects/arrays as RDF triples:

  1. JSON objects map to RDF resources that, depending on the arguments that you provide to json2rdf, can be either URIs or blank nodes.
  2. Fields of the JSON objects maps to properties.
  3. JSON arrays map to RDF Sequences.
  4. JSON primitive types String, Number and Boolean maps to corresponding XSD types, xsd:string, xsd:int and xsd:boolean.
  5. By default, json2rdf maps JSON objects/arrays to blank nodes. However, you can use --uri-root argument to map JSON objects/arrays to URIs. In this case the URI that you pass to json2rdf as argument for --uri-root will be the URI of the root JSON object/array. URIs for the nested JSON objects/arrays will be derived by concatenating the URI of the root and the JSON path of the JSON object/array.
  6. json2rdf is meant to extract the content of a JSON file, therefore null values correspond to no triples (cf. W3C discussion about this topic).

Preliminaries

You can compile and execute json2rdf using maven, as follows

mvn clean install 
mvn exec:java -Dexec.mainClass="eu.spice.json2rdf.JSON2RDF" -Dexec.args="..."

Usage

usage: json2rdf
 -i,--input <arg>                   MANDATORY - The path to the JSON file to transform.
 -o,--output <arg>                  OPTIONAL - The path to the RDF file to be generated. [Default: STD-OUT]
 -p,--prefix-for-properties <arg>   OPTIONAL - The namespace prefix for the properties to be generated. [Default: https://w3id.org/spice/ontology/]
 -r,--uri-root <arg>                OPTIONAL - The URI of the root resource. [Default: https://w3id.org/spice/resource/root]
 -s,--syntax <arg>                  OPTIONAL - The RDF syntax of the output file. [Default: TTL]

Transformation Examples

A bunch of examples of transformations

Arguments Input File Output
{
"stringArg":"stringValue",
"intArg":1,
"booleanArg":true,
"nullArg": null,
"arr":[0,1]
}
@prefix ex:    <https://w3id.org/spice/ontology/> .

[ a rdfs:Resource ;
ex:arr [ a rdf:Seq ;
rdf:_0 "0"^^xsd:int ;
rdf:_1 "1"^^xsd:int
] ;
ex:booleanArg true ;
ex:intArg "1"^^xsd:int ;
ex:stringArg "stringValue"
] .
["a",1,true,null,{"id":"a"}]
@prefix ex:    <https://w3id.org/spice/ontology/> .

[ a rdf:Seq ;
rdf:_0 "a" ;
rdf:_1 "1"^^xsd:int ;
rdf:_2 true ;
rdf:_4 [ a rdfs:Resource ;
ex:id "a"
]
] .
-r https://w3id.org/spice/resource/root
{
"stringArg":"stringValue",
"intArg":1,
"booleanArg":true,
"nullArg": null,
"arr":[0,1]
}
@prefix ex:    <https://w3id.org/spice/ontology/> .

<https://w3id.org/spice/resource/root>
a rdfs:Resource ;
ex:arr <https://w3id.org/spice/resource/root/arr> ;
ex:booleanArg true ;
ex:intArg "1"^^xsd:int ;
ex:stringArg "stringValue" .

<https://w3id.org/spice/resource/root/arr>
a rdf:Seq ;
rdf:_0 "0"^^xsd:int ;
rdf:_1 "1"^^xsd:int .

License

json2rdf is licensed under Apache 2.0.

About

json2rdf implements a series of straightforward assumptions for serving the content of JSON objects/arrays as RDF triples

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages