PostgreSQL Source Code  git master
jsonfuncs.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * jsonfuncs.h
4  * Functions to process JSON data types.
5  *
6  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * src/include/utils/jsonfuncs.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 
14 #ifndef JSONFUNCS_H
15 #define JSONFUNCS_H
16 
17 #include "common/jsonapi.h"
18 #include "utils/jsonb.h"
19 
20 /*
21  * Flag types for iterate_json(b)_values to specify what elements from a
22  * json(b) document we want to iterate.
23  */
24 typedef enum JsonToIndex
25 {
26  jtiKey = 0x01,
27  jtiString = 0x02,
28  jtiNumeric = 0x04,
29  jtiBool = 0x08,
31 } JsonToIndex;
32 
33 /* an action that will be applied to each value in iterate_json(b)_values functions */
34 typedef void (*JsonIterateStringValuesAction) (void *state, char *elem_value, int elem_len);
35 
36 /* an action that will be applied to each value in transform_json(b)_values functions */
37 typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, int elem_len);
38 
39 /* build a JsonLexContext from a text datum */
40 extern JsonLexContext *makeJsonLexContext(text *json, bool need_escapes);
41 
42 /* try to parse json, and ereport(ERROR) on failure */
44 
45 /* report an error during json lexing or parsing */
47 
49 extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state,
51 extern void iterate_json_values(text *json, uint32 flags, void *action_state,
53 extern Jsonb *transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
54  JsonTransformStringValuesAction transform_action);
55 extern text *transform_json_string_values(text *json, void *action_state,
56  JsonTransformStringValuesAction transform_action);
57 
58 #endif
JsonbIterState state
Definition: jsonb.h:372
Definition: jsonb.h:220
static void error(void)
Definition: sql-dyntest.c:147
JsonLexContext * makeJsonLexContext(text *json, bool need_escapes)
Definition: jsonfuncs.c:513
Jsonb * transform_jsonb_string_values(Jsonb *jsonb, void *action_state, JsonTransformStringValuesAction transform_action)
Definition: jsonfuncs.c:5283
void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state, JsonIterateStringValuesAction action)
Definition: jsonfuncs.c:5146
unsigned int uint32
Definition: c.h:374
void iterate_json_values(text *json, uint32 flags, void *action_state, JsonIterateStringValuesAction action)
Definition: jsonfuncs.c:5214
JsonToIndex
Definition: jsonfuncs.h:24
uint32 parse_jsonb_index_flags(Jsonb *jb)
Definition: jsonfuncs.c:5078
JsonParseErrorType
Definition: jsonapi.h:36
text * transform_json_string_values(text *json, void *action_state, JsonTransformStringValuesAction transform_action)
Definition: jsonfuncs.c:5328
void pg_parse_json_or_ereport(JsonLexContext *lex, JsonSemAction *sem)
Definition: jsonfuncs.c:497
void(* JsonIterateStringValuesAction)(void *state, char *elem_value, int elem_len)
Definition: jsonfuncs.h:34
Definition: regguts.h:298
Definition: c.h:562
text *(* JsonTransformStringValuesAction)(void *state, char *elem_value, int elem_len)
Definition: jsonfuncs.h:37
void json_ereport_error(JsonParseErrorType error, JsonLexContext *lex)
Definition: jsonfuncs.c:607