json2rdf implements a series of straightforward assumptions for serving the content of JSON objects/arrays as RDF triples:
- JSON objects map to RDF resources that, depending on the arguments that you provide to json2rdf, can be either URIs or blank nodes.
- Fields of the JSON objects maps to properties.
- JSON arrays map to RDF Sequences.
- JSON primitive types String, Number and Boolean maps to corresponding XSD types,
xsd:string
,xsd:int
andxsd:boolean
. - 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. - json2rdf is meant to extract the content of a JSON file, therefore
null
values correspond to no triples (cf. W3C discussion about this topic).
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: 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]
A bunch of examples of transformations
Arguments | Input File | Output |
---|---|---|
{ |
@prefix ex: <https://w3id.org/spice/ontology/> . |
|
["a",1,true,null,{"id":"a"}] |
@prefix ex: <https://w3id.org/spice/ontology/> . |
|
-r https://w3id.org/spice/resource/root |
{ |
@prefix ex: <https://w3id.org/spice/ontology/> . |
json2rdf is licensed under Apache 2.0.