Library for convenient JSON objects initialization without memory allocations.
You can see examples sources here.
#include<stdlib.h>#include<stdio.h>#include<static-json-builder.h>intmain(void)
{
Jsonjson=JsonObject( /* { */JsonProp("items", JsonArray( /* "items": [ */JsonNull(), /* null, */JsonBool(true), /* true, */JsonInt(1), /* 1, */JsonString("hello") /* "hello", */
)) /* ], */
); /* }, */char*string=NULL;
char*buffer=malloc(json_stingified_size(json));
string=json_stringify(json);
json_stringify_into_buffer(json, buffer);
printf("%s\n", string); /* {"items":[null,true,1,"hello"]} */printf("%s\n", buffer); /* {"items":[null,true,1,"hello"]} */free(string);
free(buffer);
return0;
}$ meson build -Dbuildtype=release -Dtests=true
$ cd build
$ meson test
$ meson compile
$ sudo meson installThe library supports pkg-config, which makes linking easier and more convenient.
👍 Single header version is also supported!
cmake_minimum_required(VERSION3.14)
project(program)
find_package(PkgConfig)
pkg_check_modules(StaticJsonBuilderREQUIREDIMPORTED_TARGETstatic-json-builder)
add_executable(programexample.c)
target_link_libraries(programPUBLICPkgConfig::StaticJsonBuilder)