53 lines
1.3 KiB
C
53 lines
1.3 KiB
C
#ifndef JSON_H
|
|
#define JSON_H
|
|
|
|
#include <stdio.h>
|
|
|
|
typedef enum Whitespace {
|
|
MINIFIED,
|
|
INDENT_1,
|
|
INDENT_2,
|
|
INDENT_3,
|
|
INDENT_4,
|
|
INDENT_8,
|
|
INDENT_TAB,
|
|
} Whitespace;
|
|
|
|
typedef enum Punctuation {
|
|
BEGINNING,
|
|
NONE,
|
|
COMMA,
|
|
COLON,
|
|
} Punctuation;
|
|
|
|
typedef struct Json {
|
|
FILE* stream;
|
|
Whitespace whitespace;
|
|
int indent_level;
|
|
Punctuation next_punctuation;
|
|
} Json;
|
|
|
|
Json json_init(FILE* stream, Whitespace whitespace);
|
|
void json_free(Json* json);
|
|
|
|
void json_begin_array(Json* json);
|
|
void json_end_array(Json* json);
|
|
void json_begin_object(Json* json);
|
|
void json_end_object(Json* json);
|
|
void json_add_object_field(Json* json, const char* key);
|
|
void json_add_string(Json* json, const char* value);
|
|
void json_add_long(Json* json, long value);
|
|
void json_add_double(Json* json, double value);
|
|
void json_add_bool(Json* json, bool value);
|
|
void json_add_null(Json* json);
|
|
|
|
#define json_add_number(json, value) \
|
|
_Generic( \
|
|
(value), \
|
|
int: json_add_long((json), (long)value), \
|
|
long: json_add_long((json), value), \
|
|
float: json_add_double((json), (double)value), \
|
|
double: json_add_double((json), value))
|
|
|
|
#endif // JSON_H
|
|
|