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
|
#ifndef JSON2_H
#define JSON2_H
#include "postgres.h"
#include "lib/stringinfo.h"
#include "mb/pg_wchar.h"
typedef struct varlena json_varlena;
#define DatumGetJSONPP(X) ((json_varlena *) PG_DETOAST_DATUM_PACKED(X))
#define JSONPGetDatum(X) PointerGetDatum(X)
#define PG_GETARG_JSON_PP(n) DatumGetJSONPP(PG_GETARG_DATUM(n))
#define PG_RETURN_JSON_P(x) PG_RETURN_POINTER(x)
/* Keep the order of these enum entries in sync with
* enum_type_names[] in json_op.c . */
typedef enum
{
JSON_NULL,
JSON_STRING,
JSON_NUMBER,
JSON_BOOL,
JSON_OBJECT,
JSON_ARRAY,
JSON_TYPE_COUNT = JSON_ARRAY + 1,
JSON_INVALID
} JsonType;
#define json_type_is_valid(type) ((type) >= 0 && (type) < JSON_TYPE_COUNT)
bool json_validate(const char *str, size_t length);
bool json_validate_nospace(const char *str, size_t length);
char *json_condense(const char *json_str, size_t length, size_t *out_length);
bool json_need_to_escape_unicode(void);
char *json_escape_unicode(const char *json, size_t length, size_t *out_length);
char *json_stringify(const char *json, size_t length,
const char *space, size_t space_length,
size_t *out_length);
JsonType json_get_type(int c);
void report_corrupt_json(void);
#endif
|