Copy from JSON
You can copy from JSON directly into Kùzu using the COPY FROM
command. To use this feature,
you have to install the JSON
extension using the instructions shown here.
Consider the following JSON file:
Copy to node table
The following example creates a node table Person
and copies data from a JSON file people.json
into it:
See the JSON
extension documentation for more related features on working with JSON files.
Copy to relationship table
To copy from a JSON file to a relationship table, the relationship JSON file must contain
the "from"
and "to"
keys. We’ll need two more JSON files to complete this example.
The condition.json
file contains medical conditions that patients can have, while the has_condition.json
indicates which patients have which conditions.
As mentioned, to copy relationships, a from
and to
key are essential in the JSON file. Any other keys that
are not "from"
or "to"
are treated as relationship properties.
First, let’s create a node table called Condition
:
Next, let’s create a relationship table HAS_CONDITION
:
The has_condition.json
file can then directly be copied into the relationship table that was just created.
See the JSON
extension documentation for more related features on working with JSON files.
Ignoring erroneous rows
Like for CSV files, Kùzu can skip rows when some types of errors are encountered when importing from JSON. However, now every error type that is skippable by the CSV reader can be skipped by the JSON reader. See the Ignore erroneous rows section for more details.