#include #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); }