Skip to content

Commit

Permalink
attempting to fix VSCode compile
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiragH25 committed Apr 17, 2024
1 parent 14950bd commit 11a747a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
7 changes: 7 additions & 0 deletions doc/apiref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,13 @@ allowed in object keys.
Get a value corresponding to *key* from *object*. Returns *NULL* if
*key* is not found and on error.

.. function:: json_t *json_object_get_path(const json_t* object, size_t depth, ...)

.. refcounting:: borrow

Get a value corresponding to the path from *object*. Returns *NULL* if
the object is not found and on error.

.. function:: json_t *json_object_getn(const json_t *object, const char *key, size_t key_len)

.. refcounting:: borrow
Expand Down
1 change: 1 addition & 0 deletions src/jansson.def
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ EXPORTS
json_object_size
json_object_get
json_object_getn
json_object_get_path
json_object_set_new
json_object_setn_new
json_object_set_new_nocheck
Expand Down
2 changes: 1 addition & 1 deletion src/jansson.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void json_object_seed(size_t seed);
size_t json_object_size(const json_t *object);
json_t *json_object_get(const json_t *object, const char *key)
JANSSON_ATTRS((warn_unused_result));
json_t *json_object_get_path(const json_t* root, size_t depth, ...);
json_t *json_object_get_path(const json_t* object, size_t depth, ...);
json_t *json_object_getn(const json_t *object, const char *key, size_t key_len)
JANSSON_ATTRS((warn_unused_result));
int json_object_set_new(json_t *object, const char *key, json_t *value);
Expand Down
8 changes: 6 additions & 2 deletions src/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ json_t *json_object_get(const json_t *json, const char *key) {

json_t *json_object_get_path(json_t* object, size_t depth, ...){
va_list path;
size_t i = 0;

va_start(path, depth);
for (size_t i = 0; i < depth; i++)
{

for (i = 0; i < depth; i++){
if(object->type == JSON_ARRAY){
object = json_array_get(object, va_arg(path, size_t));
if(!object){
Expand All @@ -125,6 +127,8 @@ json_t *json_object_get_path(json_t* object, size_t depth, ...){
}
}

va_end(path);

return object;
}

Expand Down

0 comments on commit 11a747a

Please sign in to comment.