Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes16kdownloads
jsonfuncs.h67 linesDownload Raw Back to utils
1/*-------------------------------------------------------------------------2 *3 * jsonfuncs.h4 *	  Functions to process JSON data types.5 *6 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group7 * Portions Copyright (c) 1994, Regents of the University of California8 *9 * src/include/utils/jsonfuncs.h10 *11 *-------------------------------------------------------------------------12 */13 14#ifndef JSONFUNCS_H15#define JSONFUNCS_H16 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 a22 * json(b) document we want to iterate.23 */24typedef enum JsonToIndex25{26	jtiKey = 0x01,27	jtiString = 0x02,28	jtiNumeric = 0x04,29	jtiBool = 0x08,30	jtiAll = jtiKey | jtiString | jtiNumeric | jtiBool31} JsonToIndex;32 33/* an action that will be applied to each value in iterate_json(b)_values functions */34typedef 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 */37typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, int elem_len);38 39/* build a JsonLexContext from a text datum */40extern JsonLexContext *makeJsonLexContext(text *json, bool need_escapes);41 42/* try to parse json, and errsave(escontext) on failure */43extern bool pg_parse_json_or_errsave(JsonLexContext *lex, JsonSemAction *sem,44									 struct Node *escontext);45 46#define pg_parse_json_or_ereport(lex, sem) \47	(void) pg_parse_json_or_errsave(lex, sem, NULL)48 49/* save an error during json lexing or parsing */50extern void json_errsave_error(JsonParseErrorType error, JsonLexContext *lex,51							   struct Node *escontext);52 53/* get first JSON token */54extern JsonTokenType json_get_first_token(text *json, bool throw_error);55 56extern uint32 parse_jsonb_index_flags(Jsonb *jb);57extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state,58								 JsonIterateStringValuesAction action);59extern void iterate_json_values(text *json, uint32 flags, void *action_state,60								JsonIterateStringValuesAction action);61extern Jsonb *transform_jsonb_string_values(Jsonb *jsonb, void *action_state,62											JsonTransformStringValuesAction transform_action);63extern text *transform_json_string_values(text *json, void *action_state,64										  JsonTransformStringValuesAction transform_action);65 66#endif67 
codekingpro/portable-devtools · Team Ai