PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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 "nodes/nodes.h"
19#include "utils/jsonb.h"
20
21/*
22 * Flag types for iterate_json(b)_values to specify what elements from a
23 * json(b) document we want to iterate.
24 */
33
34/* an action that will be applied to each value in iterate_json(b)_values functions */
36
37/* an action that will be applied to each value in transform_json(b)_values functions */
38typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, int elem_len);
39
40/* build a JsonLexContext from a text datum; see also freeJsonLexContext */
41extern JsonLexContext *makeJsonLexContext(JsonLexContext *lex, text *json, bool need_escapes);
42
43/* try to parse json, and errsave(escontext) on failure */
45 struct Node *escontext);
46
47#define pg_parse_json_or_ereport(lex, sem) \
48 (void) pg_parse_json_or_errsave(lex, sem, NULL)
49
50/* save an error during json lexing or parsing */
52 struct Node *escontext);
53
54/* get first JSON token */
56
58extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state,
60extern void iterate_json_values(text *json, uint32 flags, void *action_state,
62extern Jsonb *transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
64extern text *transform_json_string_values(text *json, void *action_state,
66
67/* Type categories returned by json_categorize_type */
68typedef enum
69{
70 JSONTYPE_NULL, /* null, so we didn't bother to identify */
71 JSONTYPE_BOOL, /* boolean (built-in types only) */
72 JSONTYPE_NUMERIC, /* numeric (ditto) */
73 JSONTYPE_DATE, /* we use special formatting for datetimes */
76 JSONTYPE_JSON, /* JSON (and JSONB, if not is_jsonb) */
77 JSONTYPE_JSONB, /* JSONB (if is_jsonb) */
78 JSONTYPE_ARRAY, /* array */
79 JSONTYPE_COMPOSITE, /* composite */
80 JSONTYPE_CAST, /* something with an explicit cast to JSON */
81 JSONTYPE_OTHER, /* all else */
83
84extern void json_categorize_type(Oid typoid, bool is_jsonb,
90extern Datum jsonb_from_text(text *js, bool unique_keys);
91
93 Oid typid, int32 typmod,
94 void **cache, MemoryContext mcxt,
95 bool *isnull,
96 bool omit_quotes,
97 Node *escontext);
98
99#endif
int32_t int32
Definition c.h:542
uint32_t uint32
Definition c.h:546
long val
Definition informix.c:689
JsonParseErrorType
Definition jsonapi.h:35
JsonTokenType
Definition jsonapi.h:18
JsonLexContext * makeJsonLexContext(JsonLexContext *lex, text *json, bool need_escapes)
Definition jsonfuncs.c:540
Datum jsonb_from_text(text *js, bool unique_keys)
Definition jsonb.c:140
text * transform_json_string_values(text *json, void *action_state, JsonTransformStringValuesAction transform_action)
Definition jsonfuncs.c:5815
Datum json_populate_type(Datum json_val, Oid json_type, Oid typid, int32 typmod, void **cache, MemoryContext mcxt, bool *isnull, bool omit_quotes, Node *escontext)
Definition jsonfuncs.c:3342
JsonToIndex
Definition jsonfuncs.h:26
@ jtiKey
Definition jsonfuncs.h:27
@ jtiAll
Definition jsonfuncs.h:31
@ jtiNumeric
Definition jsonfuncs.h:29
@ jtiBool
Definition jsonfuncs.h:30
@ jtiString
Definition jsonfuncs.h:28
uint32 parse_jsonb_index_flags(Jsonb *jb)
Definition jsonfuncs.c:5559
text *(* JsonTransformStringValuesAction)(void *state, char *elem_value, int elem_len)
Definition jsonfuncs.h:38
void(* JsonIterateStringValuesAction)(void *state, char *elem_value, int elem_len)
Definition jsonfuncs.h:35
JsonTokenType json_get_first_token(text *json, bool throw_error)
Definition jsonfuncs.c:5937
JsonTypeCategory
Definition jsonfuncs.h:69
@ JSONTYPE_JSON
Definition jsonfuncs.h:76
@ JSONTYPE_NULL
Definition jsonfuncs.h:70
@ JSONTYPE_TIMESTAMP
Definition jsonfuncs.h:74
@ JSONTYPE_NUMERIC
Definition jsonfuncs.h:72
@ JSONTYPE_DATE
Definition jsonfuncs.h:73
@ JSONTYPE_BOOL
Definition jsonfuncs.h:71
@ JSONTYPE_OTHER
Definition jsonfuncs.h:81
@ JSONTYPE_CAST
Definition jsonfuncs.h:80
@ JSONTYPE_COMPOSITE
Definition jsonfuncs.h:79
@ JSONTYPE_ARRAY
Definition jsonfuncs.h:78
@ JSONTYPE_TIMESTAMPTZ
Definition jsonfuncs.h:75
@ JSONTYPE_JSONB
Definition jsonfuncs.h:77
void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state, JsonIterateStringValuesAction action)
Definition jsonfuncs.c:5627
void json_categorize_type(Oid typoid, bool is_jsonb, JsonTypeCategory *tcategory, Oid *outfuncoid)
Definition jsonfuncs.c:5964
void iterate_json_values(text *json, uint32 flags, void *action_state, JsonIterateStringValuesAction action)
Definition jsonfuncs.c:5695
void json_errsave_error(JsonParseErrorType error, JsonLexContext *lex, struct Node *escontext)
Definition jsonfuncs.c:641
Jsonb * transform_jsonb_string_values(Jsonb *jsonb, void *action_state, JsonTransformStringValuesAction transform_action)
Definition jsonfuncs.c:5769
bool pg_parse_json_or_errsave(JsonLexContext *lex, const JsonSemAction *sem, struct Node *escontext)
Definition jsonfuncs.c:519
Datum datum_to_json(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Definition json.c:764
Datum datum_to_jsonb(Datum val, JsonTypeCategory tcategory, Oid outfuncoid)
Definition jsonb.c:1149
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
static int fb(int x)
static void error(void)
Definition jsonb.h:215
Definition nodes.h:135
Definition c.h:706
static JsonSemAction sem