Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Typedefs | Enumerations | Functions

jsonapi.h File Reference

#include "lib/stringinfo.h"
Include dependency graph for jsonapi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  JsonLexContext
struct  jsonSemAction

Typedefs

typedef struct JsonLexContext JsonLexContext
typedef void(* json_struct_action )(void *state)
typedef void(* json_ofield_action )(void *state, char *fname, bool isnull)
typedef void(* json_aelem_action )(void *state, bool isnull)
typedef void(* json_scalar_action )(void *state, char *token, JsonTokenType tokentype)
typedef struct jsonSemAction jsonSemAction
typedef struct jsonSemActionJsonSemAction

Enumerations

enum  JsonTokenType {
  JSON_TOKEN_INVALID, JSON_TOKEN_STRING, JSON_TOKEN_NUMBER, JSON_TOKEN_OBJECT_START,
  JSON_TOKEN_OBJECT_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_ARRAY_END, JSON_TOKEN_COMMA,
  JSON_TOKEN_COLON, JSON_TOKEN_TRUE, JSON_TOKEN_FALSE, JSON_TOKEN_NULL,
  JSON_TOKEN_END
}

Functions

void pg_parse_json (JsonLexContext *lex, JsonSemAction sem)
JsonLexContextmakeJsonLexContext (text *json, bool need_escapes)

Typedef Documentation

typedef void(* json_aelem_action)(void *state, bool isnull)

Definition at line 66 of file jsonapi.h.

typedef void(* json_ofield_action)(void *state, char *fname, bool isnull)

Definition at line 65 of file jsonapi.h.

typedef void(* json_scalar_action)(void *state, char *token, JsonTokenType tokentype)

Definition at line 67 of file jsonapi.h.

typedef void(* json_struct_action)(void *state)

Definition at line 64 of file jsonapi.h.

typedef struct jsonSemAction * JsonSemAction
typedef struct jsonSemAction jsonSemAction

Enumeration Type Documentation

Enumerator:
JSON_TOKEN_INVALID 
JSON_TOKEN_STRING 
JSON_TOKEN_NUMBER 
JSON_TOKEN_OBJECT_START 
JSON_TOKEN_OBJECT_END 
JSON_TOKEN_ARRAY_START 
JSON_TOKEN_ARRAY_END 
JSON_TOKEN_COMMA 
JSON_TOKEN_COLON 
JSON_TOKEN_TRUE 
JSON_TOKEN_FALSE 
JSON_TOKEN_NULL 
JSON_TOKEN_END 

Definition at line 19 of file jsonapi.h.

{
    JSON_TOKEN_INVALID,
    JSON_TOKEN_STRING,
    JSON_TOKEN_NUMBER,
    JSON_TOKEN_OBJECT_START,
    JSON_TOKEN_OBJECT_END,
    JSON_TOKEN_ARRAY_START,
    JSON_TOKEN_ARRAY_END,
    JSON_TOKEN_COMMA,
    JSON_TOKEN_COLON,
    JSON_TOKEN_TRUE,
    JSON_TOKEN_FALSE,
    JSON_TOKEN_NULL,
    JSON_TOKEN_END,
}   JsonTokenType;


Function Documentation

JsonLexContext* makeJsonLexContext ( text json,
bool  need_escapes 
)
void pg_parse_json ( JsonLexContext lex,
JsonSemAction  sem 
)

Definition at line 263 of file json.c.

References json_lex(), JSON_PARSE_END, JSON_TOKEN_ARRAY_START, JSON_TOKEN_END, JSON_TOKEN_OBJECT_START, lex_expect(), lex_peek(), parse_array(), parse_object(), and parse_scalar().

Referenced by each_worker(), get_json_object_as_hash(), get_worker(), json_array_elements(), json_array_length(), json_in(), json_object_keys(), json_populate_recordset(), and json_recv().

{
    JsonTokenType tok;

    /* get the initial token */
    json_lex(lex);

    tok = lex_peek(lex);

    /* parse by recursive descent */
    switch (tok)
    {
        case JSON_TOKEN_OBJECT_START:
            parse_object(lex, sem);
            break;
        case JSON_TOKEN_ARRAY_START:
            parse_array(lex, sem);
            break;
        default:
            parse_scalar(lex, sem);     /* json can be a bare scalar */
    }

    lex_expect(JSON_PARSE_END, lex, JSON_TOKEN_END);

}