Groonga
Loading...
Searching...
No Matches
json.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct _grn_json_parser grn_json_parser
 JSON parser that parses JSON text (GRN_DB_TEXT) and stores parsed JSON as GRN_DB_JSON.
 
typedef struct _grn_json_reader grn_json_reader
 JSON reader that readers values from parses JSON (GRN_DB_JSON).
 
typedef struct _grn_json_path grn_json_path
 JSONPath that represents path of values in JSON.
 

Enumerations

enum  grn_json_value_type {
  GRN_JSON_VALUE_UNKNOWN , GRN_JSON_VALUE_NULL , GRN_JSON_VALUE_FALSE , GRN_JSON_VALUE_TRUE ,
  GRN_JSON_VALUE_INT64 , GRN_JSON_VALUE_FLOAT , GRN_JSON_VALUE_STRING , GRN_JSON_VALUE_ARRAY ,
  GRN_JSON_VALUE_OBJECT
}
 JSON value type. More...
 

Functions

GRN_API grn_json_parsergrn_json_parser_open (grn_ctx *ctx, grn_obj *input, grn_obj *output)
 Open a new JSON parser.
 
GRN_API grn_rc grn_json_parser_close (grn_ctx *ctx, grn_json_parser *parser)
 Close a JSON parser.
 
GRN_API grn_rc grn_json_parser_parse (grn_ctx *ctx, grn_json_parser *parser)
 Parse the given JSON text.
 
GRN_API grn_json_readergrn_json_reader_open (grn_ctx *ctx, grn_obj *json)
 Open a new JSON reader.
 
GRN_API grn_rc grn_json_reader_close (grn_ctx *ctx, grn_json_reader *reader)
 Close a JSON reader.
 
GRN_API const char * grn_json_value_type_to_string (grn_json_value_type type)
 Stringify grn_json_value_type.
 
GRN_API grn_rc grn_json_reader_next (grn_ctx *ctx, grn_json_reader *reader)
 Move to the next value.
 
GRN_API grn_json_value_type grn_json_reader_get_type (grn_ctx *ctx, grn_json_reader *reader)
 Return the current value type.
 
GRN_API grn_objgrn_json_reader_get_value (grn_ctx *ctx, grn_json_reader *reader)
 Return the current value.
 
GRN_API size_t grn_json_reader_get_size (grn_ctx *ctx, grn_json_reader *reader)
 Return the size of the current value.
 
GRN_API grn_rc grn_json_to_string (grn_ctx *ctx, grn_obj *json, grn_obj *buffer)
 Stringify parsed JSON.
 
GRN_API grn_json_pathgrn_json_path_open (grn_ctx *ctx, const char *path, int64_t path_length)
 Open a new JSONPath.
 
GRN_API grn_rc grn_json_path_close (grn_ctx *ctx, grn_json_path *path)
 Close a JSONPath.
 
GRN_API grn_rc grn_json_extract (grn_ctx *ctx, grn_obj *json, grn_json_path *path, grn_obj *values)
 Extract values specified by JSONPath in a parsed JSON.
 

Typedef Documentation

◆ grn_json_parser

typedef struct _grn_json_parser grn_json_parser

JSON parser that parses JSON text (GRN_DB_TEXT) and stores parsed JSON as GRN_DB_JSON.

Since
15.2.2

◆ grn_json_path

typedef struct _grn_json_path grn_json_path

JSONPath that represents path of values in JSON.

Since
16.0.6

◆ grn_json_reader

typedef struct _grn_json_reader grn_json_reader

JSON reader that readers values from parses JSON (GRN_DB_JSON).

Since
15.2.2

Enumeration Type Documentation

◆ grn_json_value_type

JSON value type.

Since
15.2.2
Enumerator
GRN_JSON_VALUE_UNKNOWN 
GRN_JSON_VALUE_NULL 
GRN_JSON_VALUE_FALSE 
GRN_JSON_VALUE_TRUE 
GRN_JSON_VALUE_INT64 
GRN_JSON_VALUE_FLOAT 
GRN_JSON_VALUE_STRING 
GRN_JSON_VALUE_ARRAY 
GRN_JSON_VALUE_OBJECT 

Function Documentation

◆ grn_json_extract()

GRN_API grn_rc grn_json_extract ( grn_ctx ctx,
grn_obj json,
grn_json_path path,
grn_obj values 
)

Extract values specified by JSONPath in a parsed JSON.

Parameters
ctxThe context object.
jsonThe JSON to extract.
pathThe JSONPath that specifies values.
valuesThe output values. This must be initialized by GRN_VALUE_VAR_SIZE_INIT(&values, GRN_OBJ_VECTOR, GRN_ID_NIL) or grn_obj_open(ctx, GRN_VECTOR, 0, GRN_ID_NIL).
Returns
GRN_SUCCESS on success, the appropriate grn_rc on error.
Since
16.0.6

◆ grn_json_parser_close()

GRN_API grn_rc grn_json_parser_close ( grn_ctx ctx,
grn_json_parser parser 
)

Close a JSON parser.

Parameters
ctxThe context object.
parserThe parser to close.
Returns
GRN_SUCCESS on success, the appropriate grn_rc on error.
Since
15.2.2

◆ grn_json_parser_open()

GRN_API grn_json_parser * grn_json_parser_open ( grn_ctx ctx,
grn_obj input,
grn_obj output 
)

Open a new JSON parser.

Parameters
ctxThe context object.
inputThe JSON text.
outputThe parsed JSON.
Returns
A newly created JSON parser on success, NULL on error.
Since
15.2.2

◆ grn_json_parser_parse()

GRN_API grn_rc grn_json_parser_parse ( grn_ctx ctx,
grn_json_parser parser 
)

Parse the given JSON text.

Parameters
ctxThe context object.
parserThe parser.
Returns
GRN_SUCCESS on success, the appropriate grn_rc on error.
Since
15.2.2

◆ grn_json_path_close()

GRN_API grn_rc grn_json_path_close ( grn_ctx ctx,
grn_json_path path 
)

Close a JSONPath.

Parameters
ctxThe context object.
pathThe path to close.
Returns
GRN_SUCCESS on success, the appropriate grn_rc on error.
Since
16.0.6

◆ grn_json_path_open()

GRN_API grn_json_path * grn_json_path_open ( grn_ctx ctx,
const char *  path,
int64_t  path_length 
)

Open a new JSONPath.

Parameters
ctxThe context object.
pathThe JSONPath to parse.
path_lengthThe byte size of path. You can use -1 if path is a \0-terminated string.
Returns
A newly created JSONPath on success, NULL on error.
Since
16.0.6

◆ grn_json_reader_close()

GRN_API grn_rc grn_json_reader_close ( grn_ctx ctx,
grn_json_reader reader 
)

Close a JSON reader.

Parameters
ctxThe context object.
readerThe reader to close.
Returns
GRN_SUCCESS on success, the appropriate grn_rc on error.
Since
15.2.2

◆ grn_json_reader_get_size()

GRN_API size_t grn_json_reader_get_size ( grn_ctx ctx,
grn_json_reader reader 
)

Return the size of the current value.

Parameters
ctxThe context object.
readerThe reader.
Returns
If the current value is an array, the number of elements.
    If the current value is an object, the number of members.

    Otherwise, `0`.
Since
15.2.2

◆ grn_json_reader_get_type()

GRN_API grn_json_value_type grn_json_reader_get_type ( grn_ctx ctx,
grn_json_reader reader 
)

Return the current value type.

Parameters
ctxThe context object.
readerThe reader.
Returns
If the current value is null, GRN_JSON_VALUE_NULL.
    If the current value is `false`, \ref GRN_JSON_VALUE_FALSE.

    If the current value is `true`, \ref GRN_JSON_VALUE_TRUE.

    If the current value is an integer, \ref
    GRN_JSON_VALUE_INT64.

    If the current value is a floating-point number, \ref
    GRN_JSON_VALUE_FLOAT.

    If the current value is a string, \ref
    GRN_JSON_VALUE_STRING.

    If the current value is an array, \ref
    GRN_JSON_VALUE_ARRAY.

    If the current value is an array, \ref
    GRN_JSON_VALUE_OBJECT.

    Otherwise, \ref GRN_JSON_VALUE_UNKNOWN.
Since
15.2.2

◆ grn_json_reader_get_value()

GRN_API grn_obj * grn_json_reader_get_value ( grn_ctx ctx,
grn_json_reader reader 
)

Return the current value.

This is owned by the reader. Caller must not free it. The returned value is invalid when you call grn_json_reader_next. If you want to use this after the next grn_json_reader_next call, you need to copy this by yourself.

Parameters
ctxThe context object.
readerThe reader.
Returns
If the current value is null, GRN_DB_VOID bulk.
    If the current value is `false` or `true`, \ref GRN_DB_BOOL
    bulk.

    If the current value is an integer, \ref GRN_DB_INT64 bulk.

    If the current value is a floating-point number, \ref
    GRN_DB_FLOAT bulk.

    If the current value is a string, \ref GRN_DB_TEXT bulk.

    Otherwise, `NULL`. You can get array elements and object
    members by calling \ref grn_json_reader_next.
Since
15.2.2

◆ grn_json_reader_next()

GRN_API grn_rc grn_json_reader_next ( grn_ctx ctx,
grn_json_reader reader 
)

Move to the next value.

The initial state doesn't focus on any value. You must call this at least once. This returns GRN_END_OF_DATA when all values are processed. So you can use the following loop:

if (!reader) {
// Process error
}
while (true) {
grn_rc rc = grn_json_reader_next(ctx, reader);
if (rc == GRN_END_OF_DATA) {
break;
}
if (rc != GRN_SUCCESS) {
// Process error.
break;
}
// Process the current value with grn_json_reader_get_type(),
// grn_json_reader_get_value() and grn_json_reader_get_size().
}
grn_json_reader_close(ctx, reader);
grn_rc
Definition groonga.h:61
@ GRN_SUCCESS
Success (0)
Definition groonga.h:63
@ GRN_END_OF_DATA
Definition groonga.h:64
GRN_API grn_rc grn_json_reader_close(grn_ctx *ctx, grn_json_reader *reader)
Close a JSON reader.
struct _grn_json_reader grn_json_reader
JSON reader that readers values from parses JSON (GRN_DB_JSON).
Definition json.h:81
GRN_API grn_json_reader * grn_json_reader_open(grn_ctx *ctx, grn_obj *json)
Open a new JSON reader.
GRN_API grn_rc grn_json_reader_next(grn_ctx *ctx, grn_json_reader *reader)
Move to the next value.
Parameters
ctxThe context object.
readerThe reader.
Returns
GRN_SUCCESS on success, GRN_END_OF_DATA on all processed, the appropriate grn_rc on error.
Since
15.2.2

◆ grn_json_reader_open()

GRN_API grn_json_reader * grn_json_reader_open ( grn_ctx ctx,
grn_obj json 
)

Open a new JSON reader.

Parameters
ctxThe context object.
jsonThe parsed JSON.
Returns
A newly created JSON reader on success, NULL on error.
Since
15.2.2

◆ grn_json_to_string()

GRN_API grn_rc grn_json_to_string ( grn_ctx ctx,
grn_obj json,
grn_obj buffer 
)

Stringify parsed JSON.

Parameters
ctxThe context object.
jsonThe JSON to stringify.
bufferThe output buffer.
Returns
GRN_SUCCESS on success, the appropriate grn_rc on error.
Since
15.2.2

◆ grn_json_value_type_to_string()

GRN_API const char * grn_json_value_type_to_string ( grn_json_value_type  type)

Stringify grn_json_value_type.

Parameters
typeThe grn_json_value_type to stringify.
Returns
The string representation of type.
Since
16.0.1