apoc.convert.fromJsonList

Function APOC Core

apoc.convert.fromJsonList('[1,2,3]'[,'json-path'])

Signature

apoc.convert.fromJsonList(list :: STRING?, path =  :: STRING?) :: (LIST? OF ANY?)

Input parameters

Name Type Default

list

STRING?

null

path

STRING?

Usage Examples

The following converts a JSON list into a Cypher list:

RETURN apoc.convert.fromJsonList('[1,2,3]') AS output;
Table 1. Results
Output

[1, 2, 3]

We can also use JSON path expressions to extract part of a JSON list. For example, the following extracts the name property from a JSON list of objects and returns a list of Cypher strings:

RETURN apoc.convert.fromJsonList('[
  {"name": "Neo4j"},
  {"name": "Graph Data Science Library"},
  {"name": "Bloom"}
]', '.name') AS output;
Table 2. Results
Output

["Neo4j", "Graph Data Science Library", "Bloom"]

If we try to convert a non-list structure, we’ll get an exception. For example:

RETURN apoc.convert.fromJsonList('{"name": "Neo4j"}') AS output;
Table 3. Results

Failed to invoke function apoc.convert.fromJsonList: Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.util.ArrayList<java.lang.Object> out of START_OBJECT token at [Source: (String)"{"name": "Neo4j"}"; line: 1, column: 1]

In this case we should instead use apoc.convert.fromJsonMap.