Zephyr API 3.6.99
Loading...
Searching...
No Matches
json.h File Reference
#include <zephyr/sys/util.h>
#include <stddef.h>
#include <zephyr/toolchain.h>
#include <zephyr/types.h>
#include <sys/types.h>

Go to the source code of this file.

Data Structures

struct  json_token
 
struct  json_lexer
 
struct  json_obj
 
struct  json_obj_token
 
struct  json_obj_descr
 

Macros

#define JSON_OBJ_DESCR_PRIM(struct_, field_name_, type_)
 Helper macro to declare a descriptor for supported primitive values.
 
#define JSON_OBJ_DESCR_OBJECT(struct_, field_name_, sub_descr_)
 Helper macro to declare a descriptor for an object value.
 
#define JSON_OBJ_DESCR_ARRAY(struct_, field_name_, max_len_, len_field_, elem_type_)
 Helper macro to declare a descriptor for an array of primitives.
 
#define JSON_OBJ_DESCR_OBJ_ARRAY(struct_, field_name_, max_len_, len_field_, elem_descr_, elem_descr_len_)
 Helper macro to declare a descriptor for an array of objects.
 
#define JSON_OBJ_DESCR_ARRAY_ARRAY(struct_, field_name_, max_len_, len_field_, elem_descr_, elem_descr_len_)
 Helper macro to declare a descriptor for an array of array.
 
#define JSON_OBJ_DESCR_ARRAY_ARRAY_NAMED(struct_, json_field_name_, struct_field_name_, max_len_, len_field_, elem_descr_, elem_descr_len_)
 Variant of JSON_OBJ_DESCR_ARRAY_ARRAY that can be used when the structure and JSON field names differ.
 
#define JSON_OBJ_DESCR_PRIM_NAMED(struct_, json_field_name_, struct_field_name_, type_)
 Variant of JSON_OBJ_DESCR_PRIM that can be used when the structure and JSON field names differ.
 
#define JSON_OBJ_DESCR_OBJECT_NAMED(struct_, json_field_name_, struct_field_name_, sub_descr_)
 Variant of JSON_OBJ_DESCR_OBJECT that can be used when the structure and JSON field names differ.
 
#define JSON_OBJ_DESCR_ARRAY_NAMED(struct_, json_field_name_, struct_field_name_, max_len_, len_field_, elem_type_)
 Variant of JSON_OBJ_DESCR_ARRAY that can be used when the structure and JSON field names differ.
 
#define JSON_OBJ_DESCR_OBJ_ARRAY_NAMED(struct_, json_field_name_, struct_field_name_, max_len_, len_field_, elem_descr_, elem_descr_len_)
 Variant of JSON_OBJ_DESCR_OBJ_ARRAY that can be used when the structure and JSON field names differ.
 

Typedefs

typedef int(* json_append_bytes_t) (const char *bytes, size_t len, void *data)
 Function pointer type to append bytes to a buffer while encoding JSON data.
 

Enumerations

enum  json_tokens {
  JSON_TOK_NONE = '_' , JSON_TOK_OBJECT_START = '{' , JSON_TOK_OBJECT_END = '}' , JSON_TOK_ARRAY_START = '[' ,
  JSON_TOK_ARRAY_END = ']' , JSON_TOK_STRING = '"' , JSON_TOK_COLON = ':' , JSON_TOK_COMMA = ',' ,
  JSON_TOK_NUMBER = '0' , JSON_TOK_FLOAT = '1' , JSON_TOK_OPAQUE = '2' , JSON_TOK_OBJ_ARRAY = '3' ,
  JSON_TOK_ENCODED_OBJ = '4' , JSON_TOK_INT64 = '5' , JSON_TOK_TRUE = 't' , JSON_TOK_FALSE = 'f' ,
  JSON_TOK_NULL = 'n' , JSON_TOK_ERROR = '!' , JSON_TOK_EOF = '\0'
}
 

Functions

int64_t json_obj_parse (char *json, size_t len, const struct json_obj_descr *descr, size_t descr_len, void *val)
 Parses the JSON-encoded object pointed to by json, with size len, according to the descriptor pointed to by descr.
 
int json_arr_parse (char *json, size_t len, const struct json_obj_descr *descr, void *val)
 Parses the JSON-encoded array pointed to by json, with size len, according to the descriptor pointed to by descr.
 
int json_arr_separate_object_parse_init (struct json_obj *json, char *payload, size_t len)
 Initialize single-object array parsing.
 
int json_arr_separate_parse_object (struct json_obj *json, const struct json_obj_descr *descr, size_t descr_len, void *val)
 Parse a single object from array.
 
ssize_t json_escape (char *str, size_t *len, size_t buf_size)
 Escapes the string so it can be used to encode JSON objects.
 
size_t json_calc_escaped_len (const char *str, size_t len)
 Calculates the JSON-escaped string length.
 
ssize_t json_calc_encoded_len (const struct json_obj_descr *descr, size_t descr_len, const void *val)
 Calculates the string length to fully encode an object.
 
ssize_t json_calc_encoded_arr_len (const struct json_obj_descr *descr, const void *val)
 Calculates the string length to fully encode an array.
 
int json_obj_encode_buf (const struct json_obj_descr *descr, size_t descr_len, const void *val, char *buffer, size_t buf_size)
 Encodes an object in a contiguous memory location.
 
int json_arr_encode_buf (const struct json_obj_descr *descr, const void *val, char *buffer, size_t buf_size)
 Encodes an array in a contiguous memory location.
 
int json_obj_encode (const struct json_obj_descr *descr, size_t descr_len, const void *val, json_append_bytes_t append_bytes, void *data)
 Encodes an object using an arbitrary writer function.
 
int json_arr_encode (const struct json_obj_descr *descr, const void *val, json_append_bytes_t append_bytes, void *data)
 Encodes an array using an arbitrary writer function.