Processing a JSON file

29 views
Skip to first unread message

MSV

unread,
Jun 6, 2020, 5:50:44 AM6/6/20
to TopBraid Suite Users
Hi,
we do process JSON files to get into graph containers.
we first use sml:ImportTextFile and then sml:ConvertJsonToRDF to get the data.
the issue is, in case a json property is null, that value is not coming into the graph container.

{
Name:xxxxx
Age:xx
Location:null
}
for this json, i would only get Name and Age into my graph, but i want Location value as well even if its null.

is there a better way to process the jsons?

Richard Cyganiak

unread,
Jun 6, 2020, 9:46:44 AM6/6/20
to topbraid-users list
I can't think of a good way around this. RDF can't really distinguish between an absent value and a “null value”, and the only built-in way to interact with JSON is by converting it to RDF.

Richard


--
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 topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/9cc2aacd-6cfc-4aaa-b9db-130ffa4d2185o%40googlegroups.com.

Holger Knublauch

unread,
Jun 6, 2020, 8:21:03 PM6/6/20
to topbrai...@googlegroups.com

One current option for such a scenario is to use SHACL-JS because that can be used to process arbitrary JavaScript.

https://www.w3.org/TR/shacl-js/

But the wiring won't be easy. You'll basically have to define a SHACL-JS rule or function that takes the JSON as string (loaded via sml:ImportTextFile) and then does JSON.parse() from where you can do whatever you want in JavaScript.

Another alternative is https://uispin.org/ui.html#json but I haven't tried whether this actually preserves the null values.

We will have much better alternatives for JSON processing from 6.4 onwards (beta coming soon).

Holger

Tim Smith

unread,
Jun 8, 2020, 2:45:19 PM6/8/20
to topbrai...@googlegroups.com
One thought - can you pre-process the JSON as text?  I noticed you are reading it in as a text file to begin with.  If the "null" values appear as you have shown them 

e.g. Location:null

is it possible to do a string replace to change 'null' into another value that will be retained in the conversion to triples?  After conversion, you could find the values and set them accordingly with an Update query.

Rob Atkinson

unread,
Jun 9, 2020, 9:02:24 PM6/9/20
to TopBraid Suite Users
+1 for an option to pre-process JSON.

In particular it would be good to be able to attach JSON-LD context files to control the mapping of element to RDF nodes.


On Tuesday, 9 June 2020 04:45:19 UTC+10, Tim Smith wrote:
One thought - can you pre-process the JSON as text?  I noticed you are reading it in as a text file to begin with.  If the "null" values appear as you have shown them 

e.g. Location:null

is it possible to do a string replace to change 'null' into another value that will be retained in the conversion to triples?  After conversion, you could find the values and set them accordingly with an Update query.

On Sat, Jun 6, 2020 at 8:21 PM Holger Knublauch <hol...@topquadrant.com> wrote:

One current option for such a scenario is to use SHACL-JS because that can be used to process arbitrary JavaScript.

https://www.w3.org/TR/shacl-js/

But the wiring won't be easy. You'll basically have to define a SHACL-JS rule or function that takes the JSON as string (loaded via sml:ImportTextFile) and then does JSON.parse() from where you can do whatever you want in JavaScript.

Another alternative is https://uispin.org/ui.html#json but I haven't tried whether this actually preserves the null values.

We will have much better alternatives for JSON processing from 6.4 onwards (beta coming soon).

Holger


On 6/06/2020 19:50, MSV wrote:
Hi,
we do process JSON files to get into graph containers.
we first use sml:ImportTextFile and then sml:ConvertJsonToRDF to get the data.
the issue is, in case a json property is null, that value is not coming into the graph container.

{
Name:xxxxx
Age:xx
Location:null
}
for this json, i would only get Name and Age into my graph, but i want Location value as well even if its null.

is there a better way to process the jsons?

--
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 topbrai...@googlegroups.com.

--
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 topbrai...@googlegroups.com.

MSV

unread,
Jun 10, 2020, 10:42:02 AM6/10/20
to TopBraid Suite Users
thanks all, will try these options.
Reply all
Reply to author
Forward
0 new messages