HowTo – Load JSON-LD files into Virtuoso

HowTo – Load JSON-LD files into Virtuoso

The RDF_LOAD_JSON_LD( ) function enables the loading of JSON-LD files into Virtuoso, across multiple threads and as part of a transaction as required.


RDF_LOAD_JSON_LD( ) - enables the loading of JSON-LD files into Virtuoso.


       in strg varchar, 
       in base varchar, 
       in graph varchar := null, 
       in flags integer := 0, 
       in threads int := 3,
       in transactional int := 0,
       in log_enable int := null)


strg. - text of the resource

base - base IRI to resolve relative IRIs to absolute

graph - target graph IRI, parsed triples will appear in that graph.

flags - not used currently

threads - number of threads to use in call

transactional - enable or disable transactions

log_enable - controls transaction logging and in-statement autocommit as detailed at log_enable


Given the following JSON_LD file in the database directory :

$ cat test.jsonld 
  "@context": "",
  "@id": "",
  "name": "John Lennon",
  "born": "1940-10-09",
  "spouse": ""

It can be loaded into the database with the command:

SQL> rdf_load_json_ld (file_to_string('test.jsonld'),'', 'urn:test');

Done. -- 77 msec.

producing the following graph in the database:

SQL> sparql select * from <urn:test> where {?s ?p ?o};
s                                                                                 p                                                                                 o
LONG VARCHAR                                                                      LONG VARCHAR                                                                      LONG VARCHAR
_______________________________________________________________________________                                                                                     John Lennon                                                                                        1940-10-09                                                                                 

3 Rows. -- 1 msec.



I also tried to import a JSON-LD file, but I encountered an error due to the large file size, as shown below. If there is a way to import large JSON-LD files, please let me know.

/opt/virtuoso-opensource/database/MassBank.jsonld                                                                                  2           2024.1.25 8:13.33 967
044000  2024.1.25 8:13.33 967407000  0           NULL        39000 FA008: File '/opt/virtuoso-opensource/database/MassBank.jsonld' is too large (414984612 bytes), cannot return string content large
r than 10485760 bytes

The Virtuoso RDF Bulk Loader should be used for loading large RDF datasets ie JSON-LD and other …

Does it mean that one large file needs to be split into several parts?

Depends on the size of the actual dataset. Typically anything less than 1GB can be bulk loaded as a single file. If larger then it is recommended to split which enables the bulk loader to be run across multiple threads depending on the number of cores available for optimal loading of the dataset files in parallel, improving the performance of the load, as detailed in the documentation.