mirror of
https://github.com/Jous99/F4MP.git
synced 2026-01-12 08:40:53 +01:00
54 lines
1.3 KiB
C
54 lines
1.3 KiB
C
#define ZPL_IMPLEMENTATION
|
|
#define ZPL_NANO
|
|
#define ZPL_ENABLE_JSON
|
|
#include <zpl.h>
|
|
|
|
int main(void) {
|
|
zpl_file_contents fc;
|
|
fc = zpl_file_read_contents(zpl_heap(), true, "misc/data/test.json5");
|
|
|
|
zpl_json_object root = {0};
|
|
|
|
u8 err;
|
|
zpl_json_parse(&root, fc.size, (char *)fc.data, zpl_heap_allocator(), true, &err);
|
|
|
|
zpl_json_object *replace = NULL;
|
|
replace = zpl_json_find(&root, "replace_me", false);
|
|
|
|
if (replace != NULL)
|
|
{
|
|
zpl_printf("Field was found! Current value: %ld\nReplacing with an array!\n", (long)replace->integer);
|
|
|
|
replace->type = ZPL_JSON_TYPE_ARRAY;
|
|
zpl_array_init(replace->nodes, replace->backing);
|
|
|
|
for (size_t i = 0; i < 5; i++)
|
|
{
|
|
zpl_json_object *o = zpl_json_add(replace, NULL, ZPL_JSON_TYPE_INTEGER);
|
|
|
|
if (o) {
|
|
o->integer = (i64)i+1;
|
|
}
|
|
}
|
|
|
|
replace->name = "i_am_replaced ";
|
|
}
|
|
|
|
zpl_json_object *first = zpl_json_add_at(&root, 0, "first", ZPL_JSON_TYPE_STRING);
|
|
|
|
if (first)
|
|
{
|
|
first->string = "I am first!";
|
|
first->assign_style = ZPL_JSON_ASSIGN_STYLE_EQUALS;
|
|
}
|
|
|
|
|
|
zpl_printf("Error code: %d\n", err);
|
|
|
|
zpl_json_write(zpl_file_get_standard(ZPL_FILE_STANDARD_OUTPUT), &root, 0);
|
|
|
|
zpl_json_free(&root);
|
|
|
|
zpl_file_free_contents(&fc);
|
|
return 0;
|
|
}
|