apoc.json.path

Details

Syntax

apoc.json.path(json [, path, pathOptions ])

Description

Returns the given JSON path.

Arguments

Name

Type

Description

json

STRING

A JSON string.

path

STRING

The path to extract from the JSON string. The default is: $.

pathOptions

LIST<STRING>

A list of JSON path option enum values: ALWAYS_RETURN_LIST, AS_PATH_LIST, DEFAULT_PATH_LEAF_TO_NULL, REQUIRE_PROPERTIES, SUPPRESS_EXCEPTIONS. The default is: null.

Returns

ANY

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.json.path(p.json, "$.a") AS output;
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 we can execute (with default pathOptions):

RETURN apoc.json.path('{ "columns": {
      "col2": {
        "_id": "772col2"
      }
    }
}', '$..columns') AS output;
Results
Output

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

or, with custom path options:

RETURN apoc.json.path('{ "columns": {
      "col2": {
        "_id": "772col2"
      }
    }
}', '$..columns', ['ALWAYS_RETURN_LIST']) AS output;
Results
Output

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