82 lines
2.4 KiB
C
82 lines
2.4 KiB
C
#ifndef JSON_H
|
|
#define JSON_H
|
|
|
|
#include "json_collections.h"
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
enum json_type {
|
|
json_null = 1,
|
|
json_false = 2,
|
|
json_true = 3,
|
|
json_int,
|
|
json_float,
|
|
json_string,
|
|
json_array,
|
|
json_object,
|
|
};
|
|
|
|
struct json_value;
|
|
|
|
struct json_value* json_new(enum json_type type);
|
|
void json_free(struct json_value* value);
|
|
|
|
bool json_is(struct json_value const* value, enum json_type type);
|
|
|
|
enum json_type json_get_type(struct json_value const* value);
|
|
bool json_get_bool(struct json_value const* value);
|
|
int64_t json_get_int(struct json_value const* value);
|
|
double json_get_float(struct json_value const* value);
|
|
const char* json_get_string(struct json_value const* value);
|
|
|
|
void json_set_null(struct json_value** value);
|
|
void json_set_bool(struct json_value** value, bool val);
|
|
void json_set_int(struct json_value** value, int64_t val);
|
|
void json_set_float(struct json_value** value, double val);
|
|
void json_set_string(struct json_value* value, char* val);
|
|
|
|
struct json_value* json_new_int(int64_t val);
|
|
struct json_value* json_new_float(double val);
|
|
|
|
size_t json_array_count(struct json_value const* array);
|
|
struct json_value* json_idx(struct json_value* array, size_t idx);
|
|
struct json_value const* json_idx_const(
|
|
struct json_value const* array, size_t idx);
|
|
void json_push(struct json_value* array, struct json_value* value);
|
|
|
|
struct json_value* json_key(struct json_value* object, const char* key);
|
|
struct json_value* json_key_sized(
|
|
struct json_value* object, const char* key, size_t key_size);
|
|
struct json_value const* json_key_hash_const(
|
|
struct json_value const* object, size_t hash);
|
|
void json_set(
|
|
struct json_value* object, const char* key, struct json_value* value);
|
|
void json_set_sized(struct json_value* object,
|
|
const char* key,
|
|
size_t key_size,
|
|
struct json_value* value);
|
|
void json_object_keys(struct json_value const* object,
|
|
struct hash_key_entry const** keys,
|
|
size_t* count);
|
|
|
|
struct json_value* json_parse(
|
|
const char* text, size_t text_size, struct blockalloc* alloc);
|
|
|
|
struct json_value* json_query(struct json_value* val, const char* query);
|
|
|
|
typedef int JsonWriteCb(void* self, const char* data, size_t size);
|
|
|
|
int json_stringify(
|
|
struct json_value const* node, JsonWriteCb write, void* self);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|