Initial commit
This commit is contained in:
commit
d2182a433c
9 changed files with 421 additions and 0 deletions
50
main.c
Normal file
50
main.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "json.h"
|
||||
|
||||
typedef struct Info {
|
||||
int id;
|
||||
const char* description;
|
||||
bool enabled;
|
||||
} Info;
|
||||
|
||||
#define INFO_LEN 2
|
||||
static const Info infos[INFO_LEN] = {
|
||||
(Info){
|
||||
.id = 0,
|
||||
.description = "test",
|
||||
.enabled = true,
|
||||
},
|
||||
(Info){
|
||||
.id = 1,
|
||||
.description = "Hello, World!",
|
||||
.enabled = false,
|
||||
},
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
auto json = json_init(stdout, INDENT_2);
|
||||
|
||||
json_begin_array(&json);
|
||||
for (int i = 0; i < INFO_LEN; i++) {
|
||||
auto info = infos[i];
|
||||
|
||||
json_begin_object(&json);
|
||||
{
|
||||
json_add_object_field(&json, "id");
|
||||
json_add_long(&json, info.id);
|
||||
|
||||
json_add_object_field(&json, "description");
|
||||
json_add_string(&json, info.description);
|
||||
|
||||
json_add_object_field(&json, "enabled");
|
||||
json_add_bool(&json, info.enabled);
|
||||
}
|
||||
json_end_object(&json);
|
||||
}
|
||||
json_end_array(&json);
|
||||
|
||||
json_free(&json);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue