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-2022, 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,
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 
48 /* get first JSON token */
49 extern JsonTokenType json_get_first_token(text *json, bool throw_error);
50 
52 extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state,
54 extern void iterate_json_values(text *json, uint32 flags, void *action_state,
56 extern Jsonb *transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
57  JsonTransformStringValuesAction transform_action);
58 extern text *transform_json_string_values(text *json, void *action_state,
59  JsonTransformStringValuesAction transform_action);
60 
61 extern Datum json_populate_type(Datum json_val, Oid json_type,
62  Oid typid, int32 typmod,
63  void **cache, MemoryContext mcxt, bool *isnull);
64 
65 #endif
unsigned int uint32
Definition: c.h:441
signed int int32
Definition: c.h:429
JsonParseErrorType
Definition: jsonapi.h:37
JsonTokenType
Definition: jsonapi.h:20
text * transform_json_string_values(text *json, void *action_state, JsonTransformStringValuesAction transform_action)
Definition: jsonfuncs.c:5472
Jsonb * transform_jsonb_string_values(Jsonb *jsonb, void *action_state, JsonTransformStringValuesAction transform_action)
Definition: jsonfuncs.c:5427
JsonToIndex
Definition: jsonfuncs.h:25
@ jtiKey
Definition: jsonfuncs.h:26
@ jtiAll
Definition: jsonfuncs.h:30
@ jtiNumeric
Definition: jsonfuncs.h:28
@ jtiBool
Definition: jsonfuncs.h:29
@ jtiString
Definition: jsonfuncs.h:27
void pg_parse_json_or_ereport(JsonLexContext *lex, JsonSemAction *sem)
Definition: jsonfuncs.c:501
JsonLexContext * makeJsonLexContext(text *json, bool need_escapes)
Definition: jsonfuncs.c:517
uint32 parse_jsonb_index_flags(Jsonb *jb)
Definition: jsonfuncs.c:5222
void(* JsonIterateStringValuesAction)(void *state, char *elem_value, int elem_len)
Definition: jsonfuncs.h:34
JsonTokenType json_get_first_token(text *json, bool throw_error)
Definition: jsonfuncs.c:5577
void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state, JsonIterateStringValuesAction action)
Definition: jsonfuncs.c:5290
Datum json_populate_type(Datum json_val, Oid json_type, Oid typid, int32 typmod, void **cache, MemoryContext mcxt, bool *isnull)
Definition: jsonfuncs.c:3139
void iterate_json_values(text *json, uint32 flags, void *action_state, JsonIterateStringValuesAction action)
Definition: jsonfuncs.c:5358
void json_ereport_error(JsonParseErrorType error, JsonLexContext *lex)
Definition: jsonfuncs.c:611
text *(* JsonTransformStringValuesAction)(void *state, char *elem_value, int elem_len)
Definition: jsonfuncs.h:37
uintptr_t Datum
Definition: postgres.h:411
unsigned int Oid
Definition: postgres_ext.h:31
static void error(void)
Definition: sql-dyntest.c:147
Definition: jsonb.h:221
Definition: regguts.h:318
Definition: c.h:622