-
Notifications
You must be signed in to change notification settings - Fork 73
Description
Two gripes regarding JSON_Iterate
-
JSON arrays can't hold key-value pairs, just values. Requiring
JSONPair_twhen iterating arrays unnecessarily complicates user code. IMO there should be separate APIs for iterating arrays, and iterating collections -- can likely reuse existing implementation under the hood. Doing so would make user's code easier to read, as it'd be obvious where arrays are being iterated vs. non-arrays. -
It should only require one 'index' parameter for Iterating vs. having 2 separate parameters for start and next. The function is already modifying these index parameters, so why can't it just have one
pulIndexwhere its value at entry serves asstart, and the value ofnextis written back topulIndexbefore returning?
Would be nice for JSON_Iterate:
- A parameter for specifying which array index, not index within buffer, would be nice if for example I only wanted to Iterate array[middle:end]. Sure, technically this is possible with current
startandendparameters, however these are with respect to the buffer index. A user could call aJSON_Search("array[i]", ...)and dochar *delta to compute an index, but that seems roundabout and sort of "hacky" vs. having this API honor some "array-index" parameter. - Support for reverse array traversal. It's not uncommon for JSON arrays to be sorted. For example, I might have an array of objects sorted by creation time, and I might want to traverse from oldest-to-youngest or vice versa for different scenarios, or traverse backwards if my array is large and I know I want something closer to the end.