apoc.convert.getJsonProperty

Function

apoc.convert.getJsonProperty(node NODE, key STRING, path STRING, pathOptions LIST<STRING>) - converts a serialized JSON object from the property of the given NODE into the equivalent Cypher structure (e.g. MAP, LIST<ANY>).

Signature

apoc.convert.getJsonProperty(node :: NODE, key :: STRING, path =  :: STRING, pathOptions = null :: LIST<STRING>) :: ANY

Input parameters

Name Type Default

node

NODE

null

key

STRING

null

path

STRING

pathOptions

LIST<STRING>

[]

Usage examples

The examples in this section are based on the following sample graph:

CREATE (:Person {json:'{a:[1,2,3]}'});
MATCH (p:Person)
RETURN apoc.convert.getJsonProperty(p, "json") AS output;
Table 1. Results
Output

{a: [1, 2, 3]}

MATCH (p:Person)
RETURN apoc.convert.getJsonProperty(p, "json", "$.a") AS output;
Table 2. Results
Output

[1, 2, 3]

Moreover, we can customize the Json path options, adding as third parameter (pathOptions) a list of strings, where the strings are based on Enum<Option>. The default value is ["SUPPRESS_EXCEPTIONS", "DEFAULT_PATH_LEAF_TO_NULL"]. Note that we can also insert [], that is "without options". So, with a (n:JsonPathNode {prop: '{"columns":{"col2":{"_id":"772col2"}}}'}) we can execute (with default pathOptions):

MATCH (n:JsonPathNode) RETURN apoc.convert.getJsonProperty(n, 'prop', '$..columns') AS output;
Table 3. Results
output

[ {"col2": { "_id": "772col2" }}, null, null ]

or, with custom path options:

MATCH (n:JsonPathNode) RETURN apoc.convert.getJsonProperty(n, 'prop', '$..columns',  ['ALWAYS_RETURN_LIST']) AS output;
Table 4. Results
Output

[ {"col2": { "_id": "772col2" }} ]