blob: 109b78540e4fce26de22dcf1986d637bb10fee92 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#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_CALL_CHAR
} 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 enum {
JP_REF_NODE,
JP_REF_CHAR
} JPRefType;
typedef struct {
JPRefType type;
union {
json_node *node;
struct {
const char *bytes;
size_t length;
} chr;
} u;
} JPRef;
typedef List /* jp_element* */ JSONPath;
JSONPath *jp_parse(const char *pattern);
char *jp_show(JSONPath *jp);
List /* JPRef* */ *jp_match(JSONPath *jp, json_node *json);
void jp_set(JSONPath *jp, json_node *json, json_node *value);
/* Returns the JSON encoding of the given reference. */
char *jpref_encode(JPRef *ref);
#endif
|