-
The length of a scalar value is 1. For example, the length of
1,"a",true,false, andnullis 1. -
The length of an array is the number of array elements. For example, the length of
[1, 2]is 2. -
The length of an object is the number of object members. For example, the length of
{"a": 1}is 1. -
The length of nested arrays or objects does not count. For example, the length of
{"a": [1, 2]}is 1, because the nested array[1, 2]is not calculated into length.
Syntax
Parameters
json_doc: required, the JSON document for which to return the length.
path: optional. It is used to return the length of a value within the document. The path generally starts with $ and uses . as the path separator. [] is used as the array subscript, which starts from 0.
Return value
Returns a value of the INT type. An error is returned if the JSON document is not a valid document. 0 is returned in any of the following scenarios:-
The
pathdoes not identify a value in the document. - The path is not a valid path expression.
-
The path contains the
*or**wildcard.
Examples
Example 1: Return the length of a scalar value.text
[3, 4] is not calculated into length.
text
$.Person.
$.y.
text