Hi Daniel,
there is a variety of options here.
Obviously, if the file is JSON-LD then it can be opened like any other
RDF graph, assuming it ends with .jsonld. JSON-LD has been designed with
a notion of Contexts that provide some flexibility as an on-the-fly
transform from many JSON tree structures into JSON-based graph structure.
If the file is not JSON-LD and you cannot define a suitable JSON-LD
context then you could use our generic JSON importer that can transform
any JSON into either a "default" RDF graph or into a graph that is
described using SHACL shapes. The SPARQLMotion module to invoke that
feature is sml:ConvertJSONToRDF. Here is the documentation comment of that:
---
Takes a JSON object or array (represented as text) and converts it to
RDF triples with the same structure. The result graph will only contain
the generated triples - the input graph will be ignored and may need to
be passed on with a separate sm:next relationship. The graph uses the
namespace prefix.
This module operates in two modes. By default it will use the "json"
namespace (http://topbraid.org/json#) for properties and create blank
nodes of type json:Object. However, if sml:service is set it will look
for GraphQL shapes and walk them in parallel to the JSON object tree.
The conversion will start at the JSON root and does a recursive walk
through of the JSON objects and arrays. Each JSON object becomes a
resource. Each attribute of the JSON object is mapped into a property.
In the simple case, it will pick a property from the json namespace,
e.g. attribute "firstName" becomes a property json:firstName. In simple
mode, the values of those properties depend on the JSON attribute value
and arrays are converted to rdf:Lists, JSON objects recursively become
new blank nodes. Numbers, booleans and strings become corresponding RDF
literals. In GraphQL mode, the shapes define how the mapping is
performed and the root node must be a JSON object.
Optionally, the module can bind a new variable pointing at the root
object of the new JSON data structure in RDF. This does not work if the
provided JSON string is an Array with multiple entries.
---
With the SHACL-based approach, you start by declaring the shape of the
target data, e.g. if the RDF data should use xsd:double for a property
ex:value and your JSON only contains { value: 4.2 } then the shape would
define a sh:property constraint of sh:datatype xsd:double on sh:path
ex:value. A side benefit of this design is that you can validate the
conformance of your JSON with the shapes. This topic is briefly
mentioned in this presentation (around minute 47), but you may want to
watch most of the presentation to understand the general design
philosophy of the mapping from JSON/GraphQL to RDF/SHACL:
https://www.youtube.com/watch?v=Muj0m8Qrdig
The SHACL-less alternative would be to use the default "json" namespace
and then use modules such as sml:ApplyConstruct to produce the target
triples in their respective namespaces.
Note that sml:ConvertJSONToRDF can also be called from within SWP
scripts, which is sometimes less busy than SPARQLMotion.
Speaking about SWP, there is a number of built-in features to process
arbitrary JSON on a more "native" level, and then produce whatever you
want with it, see https://uispin.org/ui.html#json
A completely different alternative is to use a 3rd party component or
program to produce the RDF/Turtle.
HTH
Holger
On 20/08/2019 03:40, Daniel Lavoie wrote:
Hi,
Does TopQuadrant has any tool allowing us to read JSON files and to
map them to produce RDF turtle files? Can SPARQLMotion do that?
Thanks
Daniel
--
You received this message because you are subscribed to the Google
Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/topbraid-users/d98fbd11-a8b3-49a4-bb8c-4350676bc0f3%40googlegroups.com
<https://groups.google.com/d/msgid/topbraid-users/d98fbd11-a8b3-49a4-bb8c-4350676bc0f3%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups "TopBraid
Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/topbraid-users/03821de0-ca59-a046-3e89-3cef20f3b979%40topquadrant.com.