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>
int main(void)
{
Json json = 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);
return 0;
}
$ meson build -Dbuildtype=release -Dtests=true
$ cd build
$ meson test
$ meson compile
$ sudo meson install
The library supports pkg-config, which makes linking easier and more convenient.
👍 Single header version is also supported!
cmake_minimum_required(VERSION 3.14)
project(program)
find_package(PkgConfig)
pkg_check_modules(StaticJsonBuilder REQUIRED IMPORTED_TARGET static-json-builder)
add_executable(program example.c)
target_link_libraries(program PUBLIC PkgConfig::StaticJsonBuilder)