DieTime / static-json-builder

Library for convenient JSON objects initialization without memory allocations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Health Check Linux Health Check MacOS Health Check Windows MinGW Health Check Windows MSVC License type: MIT Single Header Support

Library for convenient JSON objects initialization without memory allocations.

πŸ‘¨β€πŸ’» Usage

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;
}

πŸ”¨ Building, testing and installing

$ meson build -Dbuildtype=release -Dtests=true
$ cd build
$ meson test
$ meson compile
$ sudo meson install

πŸ”Œ Linking

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)

About

Library for convenient JSON objects initialization without memory allocations

License:MIT License


Languages

Language:C 96.7%Language:Meson 3.3%