Xbasic
json_get_array_length Function
Syntax
dim result as N = json_get_array_length(json as C)
Arguments
- jsonCharacter
A JSON object.
Returns
- resultNumeric
Returns the length of the JSON array.
Description
Returns the length of a JSON array.
Discussion
The json_get_array_length() function calculates the length of a JSON array. This method can be used instead of using json_parse() to convert a JSON array to an Xbasic array to get a count of the number of elements in the array. json_get_array_length() computes the array length more efficiently than converting a JSON array to an Xbasic array to compute the length.
This function is a wrapper function for the Extension::JSON getLength() method.
Output from the Interactive Window
dim json as c =<<%json%
[{
"Firstname": "John",
"Lastname": "Smith",
"City": "Boston",
"State": "MA"
},
{
"Firstname": "Henry",
"Lastname": "Rhodes",
"City": "New York",
"State": "NY"
},
{
"Firstname": "Allison",
"Lastname": "Berman",
"City": "Los Angeles",
"State": "CA"
},
{
"Firstname": "Amanda",
"Lastname": "Higgins",
"City": "Chicago",
"State": "IL"
},
{
"Firstname": "Nancy",
"Lastname": "Clark",
"City": "Boston",
"State": "MA"
},
{
"Firstname": "Cecelia",
"Lastname": "Dawkins",
"City": "Boulder",
"State": "CO"
},
{
"Firstname": "Kathy",
"Lastname": "Morton",
"City": "New York",
"State": "NY"
}]
%json%
dim length as n = json_get_array_length(json)
? length
= 7See Also