akheron / jansson

C library for encoding, decoding and manipulating JSON data
http://www.digip.org/jansson/
Other
3.06k stars 815 forks source link

Implement Variadic Object Traversal #688

Open ChiragH25 opened 5 months ago

ChiragH25 commented 5 months ago

Searches Object using a variadic function.

Function takes a root object, a depth of search and a path composed of char* keys for elements in objects and size_t indexes for objects in lists.

examples below from tests, and reference the following JSON:

{
  "base": {
    "array": [{}, [], "string 1", 1, 2.2000000000000002, true, false, null],
    "string2": "string3",
    "integer": 3,
    "real": 4.4000000000000004,
    "true": true,
    "false": false,
    "null": null,
    "nest 1": { "nest 2": { "nest 3": {} } }
  }
}

value = json_object_get_path(json, 2, "base", "array"); returns a json object for [{}, [], "string 1", 1, 2.2000000000000002, true, false, null]

value = json_object_get_path(json, 3, "base", "array", (size_t) 2); returns a json object for "string 1"

value = json_object_get_path(json, 3, "base", "nest 1", "nest 2"); returns a json object for {"nest 3":{}}

ChiragH25 commented 5 months ago

I can't seem to end the redundant appveyor calls. Is there anything I can do to compensate you if there is any harm caused? I'm really sorry about this.

ChiragH25 commented 5 months ago

So, again sorry about the appveyor thing. it's 3AM here and I can't sleep so I though I'd fix this but I didn't realise I was pushing to the PR instead of my branch.

Also, apparently removing the typechecking in the function was unnecessary, but I like it better this way