apoc.load.jsonParams
The procedure’s 'Params' name refers to the HTTP request’s headers and payload being parameterized when connecting to the given URL, not the Neo4j $ parameters.
|
Syntax |
|
||
Description |
Loads a JSON document from a URL (e.g. web-API) as a stream of values if the given JSON document is a |
||
Input arguments |
Name |
Type |
Description |
|
|
The name of the file or binary data to import the data from. Note that a URL needs to be properly encoded to conform with the URI standard. |
|
|
|
Headers to be used when connecting to the given URL. |
|
|
|
The payload to send when connecting to the given URL. |
|
|
|
A JSON path expression used to extract specific subparts of the JSON document (extracted by a JSONPath expression). . The default is: ``. |
|
|
|
|
|
Return arguments |
Name |
Type |
Description |
|
|
A map of data loaded from the given file. |
Reading from a file
By default importing from the file system is disabled.
We can enable it by setting the following property in apoc.conf
:
apoc.import.file.enabled=true
If we try to use any of the import procedures without having first set this property, we’ll get the following error message:
Failed to invoke procedure: Caused by: java.lang.RuntimeException: Import from files not enabled, please set apoc.import.file.enabled=true in your apoc.conf |
Import files are read from the import
directory, which is defined by the server.directories.import
property.
This means that any file path that we provide is relative to this directory.
If we try to read from an absolute path, such as /tmp/filename
, we’ll get an error message similar to the following one:
Failed to invoke procedure: Caused by: java.lang.RuntimeException: Can’t read url or key file:/path/to/neo4j/import/tmp/filename as json: /path/to/neo4j//import/tmp/filename (No such file or directory) |
We can enable reading files from anywhere on the file system by setting the following property in apoc.conf
:
apoc.import.file.use_neo4j_config=false
Neo4j will now be able to read from anywhere on the file system, so be sure that this is your intention before setting this property. |
Usage Examples
We can perform a GET request to a JSON endpoint by setting the config parameter method
to GET
.
The following makes a POST request to the Wikipedia Action API:
CALL apoc.load.jsonParams(
"https://en.wikipedia.org/w/api.php?action=query&titles=Neo4j&format=json&formatversion=2",
{method: "GET"},
"",
".query.pages[0]"
) YIELD value
RETURN value
value |
---|
{ "title": "Neo4j", "ns": 0, "pageid": 25505874 } |
Note that the URL needs to be properly encoded. This can be achieved using apoc.text.urlencode.
WITH apoc.text.urlencode("Auvergne-Rhône-Alpes") AS title
CALL apoc.load.jsonParams(
"https://en.wikipedia.org/w/api.php?action=query&titles="+title+"&format=json&formatversion=2",
{method: "GET"}, "", ".query.pages[0]"
) YIELD value
RETURN value.title AS title, value.pageid AS pageid
title | pageid |
---|---|
Auvergne-Rhône-Alpes" |
45093325 |