diff --git a/parson.c b/parson.c index 446d372..94c1e6c 100644 --- a/parson.c +++ b/parson.c @@ -983,14 +983,20 @@ size_t json_object_get_count(const JSON_Object *object) { } const char * json_object_get_name(const JSON_Object *object, size_t index) { - if (index >= json_object_get_count(object)) + if (object == NULL || index >= json_object_get_count(object)) return NULL; return object->names[index]; } +JSON_Value * json_object_get_value_at(const JSON_Object *object, size_t index) { + if (object == NULL || index >= json_object_get_count(object)) + return NULL; + return object->values[index]; +} + /* JSON Array API */ JSON_Value * json_array_get_value(const JSON_Array *array, size_t index) { - if (index >= json_array_get_count(array)) + if (array == NULL || index >= json_array_get_count(array)) return NULL; return array->items[index]; } diff --git a/parson.h b/parson.h index 82168c8..ef378fe 100644 --- a/parson.h +++ b/parson.h @@ -127,6 +127,7 @@ int json_object_dotget_boolean(const JSON_Object *object, const char * /* Functions to get available names */ size_t json_object_get_count(const JSON_Object *object); const char * json_object_get_name (const JSON_Object *object, size_t index); +JSON_Value * json_object_get_value_at(const JSON_Object *object, size_t index); /* Creates new name-value pair or frees and replaces old value with a new one. * json_object_set_value does not copy passed value so it shouldn't be freed afterwards. */