blob: 3d873ed609c287558f047d302927fe4cfa35f723 (
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*-------------------------------------------------------------------------
*
* jsonpath.h
* JSONPath implementation routines for JSON data type support.
*
* Copyright (c) 2010, PostgreSQL Global Development Group
* Written by Joey Adams <joeyadams3.14159@gmail.com>.
*
*-------------------------------------------------------------------------
*/
#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;
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 * json);
void jp_set(JSONPath * jp, JSON * json, JSON * value);
/* Returns the JSON encoding of the given reference. */
char *jpref_encode(JPRef * ref);
#endif
|