Documentation
¶
Overview ¶
Package json provides APOC JSON functions.
This package implements all apoc.json.* functions for working with JSON data in Cypher queries.
Index ¶
- func Compact(jsonStr string) string
- func Delete(jsonStr, path string) string
- func Filter(jsonStr string, predicate func(interface{}) bool) string
- func Flatten(jsonStr string) string
- func Keys(jsonStr string) []string
- func Map(jsonStr string, transform func(interface{}) interface{}) string
- func Merge(jsonStrs ...string) string
- func Parse(jsonStr string) interface{}
- func Path(jsonStr, path string) interface{}
- func Pretty(jsonStr string) string
- func Reduce(jsonStr string, initial interface{}, ...) interface{}
- func Set(jsonStr, path string, value interface{}) string
- func Size(jsonStr string) int
- func Stringify(value interface{}) string
- func Type(jsonStr string) string
- func Unflatten(jsonStr string) string
- func Validate(jsonStr string) bool
- func Values(jsonStr string) []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Compact ¶
Compact removes whitespace from JSON.
Example:
apoc.json.compact('{\n "name": "Alice"\n}') => '{"name":"Alice"}'
func Delete ¶
Delete removes a value from JSON at a path.
Example:
apoc.json.delete('{"name":"Alice","age":30}', '$.age')
=> '{"name":"Alice"}'
func Filter ¶
Filter filters a JSON array based on a predicate.
Example:
apoc.json.filter('[1,2,3,4,5]', 'x > 3') => '[4,5]'
func Flatten ¶
Flatten flattens a nested JSON structure.
Example:
apoc.json.flatten('{"user":{"name":"Alice"}}')
=> '{"user.name":"Alice"}'
func Keys ¶
Keys returns all keys from a JSON object.
Example:
apoc.json.keys('{"name":"Alice","age":30}') => ['name', 'age']
func Merge ¶
Merge merges multiple JSON objects.
Example:
apoc.json.merge('{"a":1}', '{"b":2}') => '{"a":1,"b":2}'
func Parse ¶
func Parse(jsonStr string) interface{}
Parse parses a JSON string into a value.
Example:
apoc.json.parse('{"name":"Alice"}') => {name: 'Alice'}
func Path ¶
func Path(jsonStr, path string) interface{}
Path extracts a value from JSON using a path expression.
Example:
apoc.json.path('{"user":{"name":"Alice"}}', '$.user.name') => 'Alice'
func Pretty ¶
Pretty formats JSON with indentation.
Example:
apoc.json.pretty('{"name":"Alice"}') => formatted JSON
func Reduce ¶
func Reduce(jsonStr string, initial interface{}, reducer func(interface{}, interface{}) interface{}) interface{}
Reduce reduces a JSON array to a single value.
Example:
apoc.json.reduce('[1,2,3,4,5]', 0, 'acc + x') => 15
func Set ¶
Set sets a value in JSON at a path.
Example:
apoc.json.set('{"user":{}}', '$.user.name', 'Alice')
=> '{"user":{"name":"Alice"}}'
func Size ¶
Size returns the size of a JSON structure.
Example:
apoc.json.size('{"name":"Alice","age":30}') => 2
apoc.json.size('[1,2,3,4,5]') => 5
func Stringify ¶
func Stringify(value interface{}) string
Stringify converts a value to JSON string.
Example:
apoc.json.stringify({name: 'Alice'}) => '{"name":"Alice"}'
func Type ¶
Type returns the type of a JSON value.
Example:
apoc.json.type('{"name":"Alice"}') => 'object'
apoc.json.type('[1,2,3]') => 'array'
func Unflatten ¶
Unflatten unflattens a flat JSON structure.
Example:
apoc.json.unflatten('{"user.name":"Alice"}')
=> '{"user":{"name":"Alice"}}'
Types ¶
This section is empty.