From f54ae52180b26e9de4524ddb912770fac399821b Mon Sep 17 00:00:00 2001 From: Martin Brown Date: Thu, 19 Jan 2012 14:06:45 -0800 Subject: [PATCH 1/4] Convenience method for accessing immediate member values of a json object. --- src/api/yajl_tree.h | 12 ++++++++++++ src/yajl_tree.c | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/src/api/yajl_tree.h b/src/api/yajl_tree.h index 729c579e..9d442518 100644 --- a/src/api/yajl_tree.h +++ b/src/api/yajl_tree.h @@ -145,6 +145,18 @@ YAJL_API void yajl_tree_free (yajl_val v); */ YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type type); +/** + * Access a value inside an object. + * + * \param object the object from which you'd like to extract values. + * \param key the key of the value in the object + * \param type the yajl_type of the object you seek, or yajl_t_any if any will do. + * + * \returns a pointer to the found value, or NULL if we came up empty. + * + */ +YAJL_API yajl_val yajl_object_get(yajl_val object, const char * key, yajl_type type); + /* Various convenience macros to check the type of a `yajl_val` */ #define YAJL_IS_STRING(v) (((v) != NULL) && ((v)->type == yajl_t_string)) #define YAJL_IS_NUMBER(v) (((v) != NULL) && ((v)->type == yajl_t_number)) diff --git a/src/yajl_tree.c b/src/yajl_tree.c index e63240cf..51251a72 100644 --- a/src/yajl_tree.c +++ b/src/yajl_tree.c @@ -452,6 +452,13 @@ yajl_val yajl_tree_parse (const char *input, return (ctx.root); } +yajl_val yajl_object_get(yajl_val n, const char * key, yajl_type type) +{ + const char ** path = {key, 0}; + yajl_val v = yajl_tree_get(n, path, type); + return v; +} + yajl_val yajl_tree_get(yajl_val n, const char ** path, yajl_type type) { if (!path) return NULL; From 0fa6968b26d122a101ab2ce544619dca0c07ec0c Mon Sep 17 00:00:00 2001 From: Martin Brown Date: Thu, 19 Jan 2012 14:20:10 -0800 Subject: [PATCH 2/4] multiple defined new function as yajl_tree_get --- src/api/yajl_tree.h | 6 +++--- src/yajl_tree.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/yajl_tree.h b/src/api/yajl_tree.h index 9d442518..4bdaee80 100644 --- a/src/api/yajl_tree.h +++ b/src/api/yajl_tree.h @@ -146,16 +146,16 @@ YAJL_API void yajl_tree_free (yajl_val v); YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type type); /** - * Access a value inside an object. + * Access an immediate value inside a tree. * - * \param object the object from which you'd like to extract values. + * \param parent the object from which you'd like to extract values. * \param key the key of the value in the object * \param type the yajl_type of the object you seek, or yajl_t_any if any will do. * * \returns a pointer to the found value, or NULL if we came up empty. * */ -YAJL_API yajl_val yajl_object_get(yajl_val object, const char * key, yajl_type type); +YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char * key, yajl_type type); /* Various convenience macros to check the type of a `yajl_val` */ #define YAJL_IS_STRING(v) (((v) != NULL) && ((v)->type == yajl_t_string)) diff --git a/src/yajl_tree.c b/src/yajl_tree.c index 51251a72..f9144231 100644 --- a/src/yajl_tree.c +++ b/src/yajl_tree.c @@ -452,7 +452,7 @@ yajl_val yajl_tree_parse (const char *input, return (ctx.root); } -yajl_val yajl_object_get(yajl_val n, const char * key, yajl_type type) +yajl_val yajl_tree_get(yajl_val n, const char * key, yajl_type type) { const char ** path = {key, 0}; yajl_val v = yajl_tree_get(n, path, type); From 5054820a02c8635996a9949943ef4a64522fce5b Mon Sep 17 00:00:00 2001 From: Martin Brown Date: Thu, 19 Jan 2012 14:21:55 -0800 Subject: [PATCH 3/4] Revert "multiple defined new function as yajl_tree_get" This reverts commit 0fa6968b26d122a101ab2ce544619dca0c07ec0c. --- src/api/yajl_tree.h | 6 +++--- src/yajl_tree.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/yajl_tree.h b/src/api/yajl_tree.h index 4bdaee80..9d442518 100644 --- a/src/api/yajl_tree.h +++ b/src/api/yajl_tree.h @@ -146,16 +146,16 @@ YAJL_API void yajl_tree_free (yajl_val v); YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char ** path, yajl_type type); /** - * Access an immediate value inside a tree. + * Access a value inside an object. * - * \param parent the object from which you'd like to extract values. + * \param object the object from which you'd like to extract values. * \param key the key of the value in the object * \param type the yajl_type of the object you seek, or yajl_t_any if any will do. * * \returns a pointer to the found value, or NULL if we came up empty. * */ -YAJL_API yajl_val yajl_tree_get(yajl_val parent, const char * key, yajl_type type); +YAJL_API yajl_val yajl_object_get(yajl_val object, const char * key, yajl_type type); /* Various convenience macros to check the type of a `yajl_val` */ #define YAJL_IS_STRING(v) (((v) != NULL) && ((v)->type == yajl_t_string)) diff --git a/src/yajl_tree.c b/src/yajl_tree.c index f9144231..51251a72 100644 --- a/src/yajl_tree.c +++ b/src/yajl_tree.c @@ -452,7 +452,7 @@ yajl_val yajl_tree_parse (const char *input, return (ctx.root); } -yajl_val yajl_tree_get(yajl_val n, const char * key, yajl_type type) +yajl_val yajl_object_get(yajl_val n, const char * key, yajl_type type) { const char ** path = {key, 0}; yajl_val v = yajl_tree_get(n, path, type); From c3734aec02cf57c9eb8d3039880970ebbfea67d2 Mon Sep 17 00:00:00 2001 From: Martin Brown Date: Thu, 19 Jan 2012 14:23:51 -0800 Subject: [PATCH 4/4] initialization error --- src/yajl_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yajl_tree.c b/src/yajl_tree.c index 51251a72..da0f5fe4 100644 --- a/src/yajl_tree.c +++ b/src/yajl_tree.c @@ -454,7 +454,7 @@ yajl_val yajl_tree_parse (const char *input, yajl_val yajl_object_get(yajl_val n, const char * key, yajl_type type) { - const char ** path = {key, 0}; + const char * path[2] = {key, 0}; yajl_val v = yajl_tree_get(n, path, type); return v; }