Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Convenience wrapper for yajl_tree_get #70

wants to merge 4 commits into from

2 participants


Hi Lloyd,

I wrote this small function to get around the awkwardness of doing

const char ** path = {"some_key", 0}
yajl_tree_get(node, path, yajl_t_any);

when I want the value from an immediate object.
Instead I can use

yajl_object_get(node, "some_key", yajl_t_any).


Martin Brown added some commits

I am curious to know what @lloyd's thoughts are on introducing this API method. sorry, I realize this is 3 years old.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 19, 2012
  1. Convenience method for accessing immediate member values of a json

    Martin Brown authored
  2. multiple defined new function as yajl_tree_get

    Martin Brown authored
  3. Revert "multiple defined new function as yajl_tree_get"

    Martin Brown authored
    This reverts commit 0fa6968b26d122a101ab2ce544619dca0c07ec0c.
  4. initialization error

    Martin Brown authored
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 0 deletions.
  1. +12 −0 src/api/yajl_tree.h
  2. +7 −0 src/yajl_tree.c
12 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))
7 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[2] = {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;
Something went wrong with that request. Please try again.