JSON.DEBUG FIELDS

Syntax

1. JSON.DEBUG fields key path

Time complexity: N/A

ACL categories: @json

Report the number of fields in the JSON element.

Return

Array reply: a list that represents the number of fields of JSON value at each path.

Examples

Check the number of fields in a JSON object. Note that the command reports the total number of fields at a path, including those from child objects.

1. dragonfly> JSON.SET obj_doc $ '{"a":1, "b":2, "c":{"k1":1,"k2":2}}'
2. OK

4. dragonfly> JSON.DEBUG fields obj_doc '$.a'
5. 1) (integer) 1

7. dragonfly> JSON.DEBUG fields obj_doc '$.b'
8. 1) (integer) 1

10. dragonfly> JSON.DEBUG fields obj_doc '$.c'
11. 1) (integer) 2

13. dragonfly> JSON.DEBUG fields obj_doc '$'
14. 1) (integer) 5

Check the number of fields in a JSON array. Note that the array itself has 9 elements. Among these 9 elements, there is one object {"a":1,"b":2} with 2 fields, and one array [1,2,3,4] with 4 fields. So in total, there are 9 + 2 + 4 = 15 fields.

1. dragonfly> JSON.SET arr_doc . '[1, 2.3, "foo", true, null, {}, [], {"a":1,"b":2}, [1,2,3,4]]'
2. OK

4. dragonfly> JSON.GET arr_doc '$[*]'
5. "[1,2.3,\"foo\",true,null,{},[],{\"a\":1,\"b\":2},[1,2,3,4]]"

7. dragonfly> JSON.DEBUG fields arr_doc '$[*]'
8. 1) (integer) 1  # 1
9. 2) (integer) 1  # 2.3
10. 3) (integer) 1  # "foo"
11. 4) (integer) 1  # true
12. 5) (integer) 1  # null
13. 6) (integer) 0  # {}
14. 7) (integer) 0  # []
15. 8) (integer) 2  # {"a":1,"b":2}
16. 9) (integer) 4  # [1,2,3,4]

18. dragonfly> JSON.DEBUG fields arr_doc '$[7,8]'
19. 1) (integer) 2  # {"a":1,"b":2}
20. 2) (integer) 4  # [1,2,3,4]

22. dragonfly> JSON.DEBUG fields arr_doc '$'
23. 1) (integer) 15