Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convenience method for accessing immediate member values of a json

object.
  • Loading branch information...
commit f54ae52180b26e9de4524ddb912770fac399821b 1 parent 8b48967
Martin Brown authored
Showing with 19 additions and 0 deletions.
  1. +12 −0 src/api/yajl_tree.h
  2. +7 −0 src/yajl_tree.c
View
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))
View
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 = {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;
Please sign in to comment.
Something went wrong with that request. Please try again.