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
  3. dragonfly> JSON.DEBUG fields obj_doc '$.a'
  4. 1) (integer) 1
  5. dragonfly> JSON.DEBUG fields obj_doc '$.b'
  6. 1) (integer) 1
  7. dragonfly> JSON.DEBUG fields obj_doc '$.c'
  8. 1) (integer) 2
  9. dragonfly> JSON.DEBUG fields obj_doc '$'
  10. 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
  3. dragonfly> JSON.GET arr_doc '$[*]'
  4. "[1,2.3,\"foo\",true,null,{},[],{\"a\":1,\"b\":2},[1,2,3,4]]"
  5. dragonfly> JSON.DEBUG fields arr_doc '$[*]'
  6. 1) (integer) 1 # 1
  7. 2) (integer) 1 # 2.3
  8. 3) (integer) 1 # "foo"
  9. 4) (integer) 1 # true
  10. 5) (integer) 1 # null
  11. 6) (integer) 0 # {}
  12. 7) (integer) 0 # []
  13. 8) (integer) 2 # {"a":1,"b":2}
  14. 9) (integer) 4 # [1,2,3,4]
  15. dragonfly> JSON.DEBUG fields arr_doc '$[7,8]'
  16. 1) (integer) 2 # {"a":1,"b":2}
  17. 2) (integer) 4 # [1,2,3,4]
  18. dragonfly> JSON.DEBUG fields arr_doc '$'
  19. 1) (integer) 15