Skip to content

Simplifying JSON_Iterate #118

Open
Open
@dachalco

Description

@dachalco

Two gripes regarding JSON_Iterate

  1. JSON arrays can't hold key-value pairs, just values. Requiring JSONPair_t when 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.

  2. 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 pulIndex where its value at entry serves as start, and the value of next is written back to pulIndex before returning?

Would be nice for JSON_Iterate:

  1. 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 start and end parameters, however these are with respect to the buffer index. A user could call a JSON_Search("array[i]", ...) and do char * delta to compute an index, but that seems roundabout and sort of "hacky" vs. having this API honor some "array-index" parameter.
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions