libgson

gsonexample.c
Login

File example/gsonexample.c from the latest check-in


#include <stdlib.h>
#include <stdio.h>
#include "gson.h"

int
main(int argc, char *argv[])
{
    (void) argc;
    (void) argv;

    struct gson *json = gson_obj_addv(NULL,
        "json null", gson_null(),
        "json booleans", gson_obj_addv(NULL,
            "true", gson_true(),
            "false", gson_false(),
            NULL),
        "json numbers", gson_arr_addv(NULL,
            gson_nbr(12),
            gson_nbr(-123.56),
            gson_nbr(1.0E+20),
            NULL),
        "json array", gson_arr_addv(NULL,
            gson_str("1rst entry"),
            gson_str("2nd entry"),
            gson_str("3rd entry"),
            NULL),
        "json object", gson_obj_addv(NULL,
            "firstname", gson_str("Jean"),
            "lastname", gson_str("Bon"),
            "age", gson_nbr(42),
            NULL),
        NULL);
    gson_print_pretty(json);
    gson_free(json);

    return EXIT_SUCCESS;
}