Skip to content

mrdrivingduck/c-json-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

c-json-generator

๐ŸŽž๏ธ A simple C JSON-string generator.

Created by : Mr Dk.

@2018.12.15, Nanjing, Jiangsu, China

I love Saturday~~~ ๐Ÿ˜†


About

It is a simple C JSON-string generator.

No support for parsing a JSON-string into a structure.

No support for reduplicated keys. (๐Ÿ˜… SORRY...)

Usage

For the simplest way to use :

  • Add dkjson.h & dkjson.c into your project
  • include #include "dkjson.h" in your source file and use it
#include <stdio.h>

int main()
{
    dkJSON json = {NULL, 0, 0};
    dkjson_init(&json);

    dkjson_put_string(&json, "str", "hahahahaha");
    dkjson_put_int(&json, "int", 21474);
    dkjson_put_short(&json, "short", 585);
    dkjson_put_float(&json, "float", 12.56f);
    dkjson_put_double(&json, "double", 12.59822221);
    dkjson_put_unsignedint(&json, "unsignedint", 2147483855);
    dkjson_put_unsignedshort(&json, "unsignedshort", 49526);

    char buf[1024];
    dkjson_generate(&json, buf);
    printf("%s\n", buf);

    dkjson_destroy(&json);
    
    return 0;
}

Notice

The memory of JSON-string will be maintained inside the structure dkJSON.

It will automatically reallocate memory if the capacity is not enough.

So, dkjson_destroy function must be called to recycle the inside maintaining memory.


About

๐ŸŽž๏ธ A simple C JSON-string generator.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published