json_util
A module for loading JSON from a local file or remote address. If the JSON that is being loaded is an array, then this module loads it as a stream of values, and if it is a map, the module loads it as a single value.
Trait | Value |
---|---|
Module type | util |
Implementation | Python |
Parallelism | sequential |
Procedures
info
If you want to execute this algorithm on graph projections, subgraphs or portions of the graph, be sure to check out the guide on How to run a MAGE module on subgraphs.
load_from_path(path)
Input:
path: string
➡ Path to the JSON that is being loaded.
Output:
objects: List[object]
➡ list of JSON objects from the file that is being loaded.
Usage:
CALL json_util.load_from_path(path)
YIELD objects
RETURN objects;
load_from_url(url)
Input:
url: string
➡ URL to the JSON that is being loaded.
Output:
objects: List[object]
➡ list of JSON objects from the file that is being loaded.
Usage:
CALL json_util.load_from_url(url)
YIELD objects
RETURN objects;
Example - Loading JSON from path
- Step 1: Input file
- Step 2: Running command
- Step 3: Results
For example, let the input path be "load-data/data.json"
. There we can find data.json
:
{
"first_name": "Jessica",
"last_name": "Rabbit",
"pets": [
"dog",
"cat",
"bird"
]
}
CALL json_util.load_from_path("load-data/data.json")
YIELD objects
UNWIND objects AS o
RETURN o.first_name AS name, o.last_name AS surname;
+------------------+-------------------+
| name | surname |
+------------------+-------------------+
| Jessica | Rabbit |
+------------------+-------------------+
Example - Loading JSON from URL
- Step 1: Input file
- Step 2: Running command
- Step 3: Results
For example, let the input URL be "https://download.memgraph.com/asset/mage/data.json"
. There we can find data.json
:
{
"first_name": "James",
"last_name": "Bond",
"pets": [
"dog",
"cat",
"fish"
]
}
CALL json_util.load_from_url("https://download.memgraph.com/asset/mage/data.json")
YIELD objects
UNWIND objects AS o
RETURN o.first_name AS name, o.last_name AS surname;
+------------------+-------------------+
| name | surname |
+------------------+-------------------+
| James | Bond |
+------------------+-------------------+