47 lines
1.0 KiB
C
47 lines
1.0 KiB
C
#ifndef JSON_H
|
|
#define JSON_H
|
|
|
|
#include <stddef.h>
|
|
|
|
typedef enum {
|
|
JSMN_UNDEFINED = 0,
|
|
JSMN_OBJECT = 1,
|
|
JSMN_ARRAY = 2,
|
|
JSMN_STRING = 3,
|
|
JSMN_PRIMITIVE = 4
|
|
} jsmntype_t;
|
|
|
|
typedef struct {
|
|
jsmntype_t type;
|
|
int start;
|
|
int end;
|
|
int size;
|
|
int parent;
|
|
} jsmntok_t;
|
|
|
|
typedef struct {
|
|
unsigned int pos;
|
|
unsigned int toknext;
|
|
int toksuper;
|
|
} jsmn_parser;
|
|
|
|
void jsmn_init(jsmn_parser *parser);
|
|
int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, jsmntok_t *tokens, unsigned int num_tokens);
|
|
|
|
typedef struct {
|
|
const char *json;
|
|
jsmntok_t *tokens;
|
|
int token_count;
|
|
} JsonDoc;
|
|
|
|
int json_doc_parse(JsonDoc *doc, const char *json);
|
|
void json_doc_free(JsonDoc *doc);
|
|
|
|
int json_token_streq(const JsonDoc *doc, int tok_idx, const char *s);
|
|
int json_skip_token(const JsonDoc *doc, int tok_idx);
|
|
int json_object_get(const JsonDoc *doc, int obj_idx, const char *key);
|
|
int json_array_get(const JsonDoc *doc, int arr_idx, int elem_index);
|
|
char *json_token_strdup(const JsonDoc *doc, int tok_idx);
|
|
|
|
#endif
|