summaryrefslogtreecommitdiff
path: root/jsonpath.h
diff options
context:
space:
mode:
authorJoey Adams2010-06-14 06:29:58 +0000
committerJoey Adams2010-06-14 06:29:58 +0000
commite8f4dc86cb87b38ee19b8574dadbbe6629f35ef0 (patch)
treed6b73069951e7decfcd9d22a94d57686694426b1 /jsonpath.h
parent042358fb35a690afdb97c12800b34af9515d15d9 (diff)
Implemented/tested parser for basic JSONPath(ish) patterns.
Diffstat (limited to 'jsonpath.h')
-rw-r--r--jsonpath.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/jsonpath.h b/jsonpath.h
new file mode 100644
index 0000000..4d19062
--- /dev/null
+++ b/jsonpath.h
@@ -0,0 +1,37 @@
+#ifndef JSONPATH_H
+#define JSONPATH_H
+
+#include "json.h"
+
+#include "nodes/pg_list.h"
+
+typedef enum {
+ JP_ROOT,
+ JP_WILDCARD,
+ JP_INDEX_SUBSCRIPT,
+ JP_KEY_SUBSCRIPT
+} jp_element_type;
+
+typedef struct {
+ jp_element_type type;
+
+ union {
+ long index;
+ struct {
+ char *ptr;
+ size_t length;
+ } key;
+ } data;
+
+ // If element was preceded by ".." in pattern
+ bool recursive_descent;
+} jp_element;
+
+typedef List JSONPath;
+
+JSONPath *jp_parse(const char *pattern);
+char *jp_show(JSONPath *jp);
+
+List *jp_match(JSONPath *jp, json_node *json);
+
+#endif