Skip to main content

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.

docs-source

TraitValue
Module typeutil
ImplementationPython
Parallelismsequential

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

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"
]
}

Example - Loading JSON from URL

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"
]
}