Returns the number of elements in a JSON array field.
Takes json string and key string.
Returns count, or 0 if key not found or not an array.
JSON
Parameters & Returns
Parameters
jsonString
keyString
Returns
Int
Quick Summary
Returns the number of elements in a JSON array field.
Takes json string and key string.
Returns count, or 0 if key not found or not an array.
Technical Exegesis...
Returns the number of elements in a JSON array field. Takes json string and key string. Calls FindKeyPosition to locate array field. If key not found, returns 0. Gets position after colon. Expects opening bracket '['. Skips opening bracket. Counts elements by tracking commas, objects, and values while respecting nested depth. Uses depth counter to track nested objects/arrays (increments on '{' or '[', decrements on '}' or ']'). Uses inString flag to track quoted strings (toggles on '\"').
Returns the number of elements in a JSON array field. Takes json string and key string. Calls FindKeyPosition to locate array field. If key not found, returns 0. Gets position after colon. Expects opening bracket '['. Skips opening bracket. Counts elements by tracking commas, objects, and values while respecting nested depth. Uses depth counter to track nested objects/arrays (increments on '{' or '[', decrements on '}' or ']'). Uses inString flag to track quoted strings (toggles on '\"'). Uses escaped flag to handle backslashes in strings. Uses foundElement flag to track element detection. Counts commas at depth 0 (not inside nested structure). Counts non-whitespace characters at depth 0 as elements (numbers, true, false, null). Adds 1 for last element if foundElement is true. Returns count, or 0 if key not found or not an array.
This function counts array elements for iteration. FindKeyPosition searches for exact key match. Depth tracking prevents counting nested array commas. String tracking prevents counting commas inside quoted strings. Handles arrays of objects, primitives, mixed types. Use to determine loop bounds for jsonGetArrayElement iteration. Returns 0 for missing keys or malformed arrays. Common pattern: count = jsonGetArrayCount(json, "items"), For i = 0 To count-1, element = jsonGetArrayElement(json, "items", i). Essential for deserializing variable-length arrays.