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.
Details

Syntax

apoc.load.jsonParams(urlOrKeyOrBinary, headers, payload [, path, config ]) :: (value)

Description

Loads a JSON document from a URL (e.g. web-API) as a stream of values if the given JSON document is a LIST<ANY>. If the given JSON file is a MAP, this procedure imports a single value instead.

Input arguments

Name

Type

Description

urlOrKeyOrBinary

ANY

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

MAP

Headers to be used when connecting to the given URL.

payload

STRING

The payload to send when connecting to the given URL.

path

STRING

A JSON path expression used to extract specific subparts of the JSON document (extracted by a JSONPath expression). . The default is: ``.

config

MAP

{ failOnError = true :: BOOLEAN, pathOptions :: LIST<STRING>, compression = "NONE" :: ["NONE", "BYTES", "GZIP", "BZIP2", "DEFLATE", "BLOCK_LZ4", "FRAMED_SNAPPY"] }. The default is: {}.

Return arguments

Name

Type

Description

value

MAP

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.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.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
Results
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
Results
title pageid

Auvergne-Rhône-Alpes"

45093325