Retrieves a specific element from a JSON array by index.
Takes json string, key string, and index integer.
Returns extracted element as string via ReturnString.
JSON
Parameters & Returns
Parameters
jsonString
keyString
indexInt
Returns
String
Quick Summary
Retrieves a specific element from a JSON array by index.
Takes json string, key string, and index integer.
Returns extracted element as string via ReturnString.
Technical Exegesis...
Retrieves a specific element from a JSON array by index. Takes json string, key string, and index integer. Calls FindKeyPosition to locate array field. If key not found, returns empty string "". Gets position after colon. Expects opening bracket '['. Skips opening bracket and whitespace. Sets elementStart to current position. Uses currentIndex counter (starts at 0). Iterates through array while tracking depth, inString, and escaped flags (same logic as jsonGetArrayCount).
Retrieves a specific element from a JSON array by index. Takes json string, key string, and index integer. Calls FindKeyPosition to locate array field. If key not found, returns empty string "". Gets position after colon. Expects opening bracket '['. Skips opening bracket and whitespace. Sets elementStart to current position. Uses currentIndex counter (starts at 0). Iterates through array while tracking depth, inString, and escaped flags (same logic as jsonGetArrayCount). At each comma or closing bracket at depth 0, checks if currentIndex matches requested index. If match found, extracts substring from elementStart to current position. Returns extracted element as string via ReturnString. If index not reached, increments currentIndex, skips whitespace, updates elementStart, continues. Returns "" if index out of bounds or key not found.
This function retrieves individual array elements by index for iteration. FindKeyPosition searches for exact key match. Depth/string tracking handles nested structures correctly. Zero-based indexing (first element is index 0). Returns element as string - caller must parse based on type (jsonReadInt for numbers, jsonReadString for strings, or recursively parse object with jsonRead* functions). Use with jsonGetArrayCount for full array iteration. Returns empty string for invalid index or missing key. Common pattern: count = jsonGetArrayCount(json, "players"), For i = 0 To count-1, player = jsonGetArrayElement(json, "players", i), name = jsonReadString(player, "name"). Enables deserializing complex nested data structures.