apoc.convert.fromJsonMap

Function APOC Core

apoc.convert.fromJsonMap('{"a":42,"b":"foo","c":[1,2,3]}'[,'json-path'])

Signature

apoc.convert.fromJsonMap(map :: STRING?, path =  :: STRING?) :: (MAP?)

Input parameters

Name Type Default

map

STRING?

null

path

STRING?

Usage Examples

The following converts a JSON map into a Cypher map:

RETURN apoc.convert.fromJsonMap('{"name": "Graph Data Science Library"}') AS output;
Table 1. Results
Output

{name: "Graph Data Science Library"}

We can also use JSON path expressions to extract part of a JSON map. For example, the following extracts the product property from a JSON map and returns a map:

RETURN apoc.convert.fromJsonMap('{"product": {"name": "Bloom"}}', '$.product') AS output;
Table 2. Results
Output

{name: "Bloom"}

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

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

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

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