Browse Source Download (without any required ccan dependencies)

Module:

json_escape

Summary:

Escape sequences for JSON strings

Author:

Rusty Russell <[email protected]>

Dependencies:

Description:

This code helps you format strings into forms useful for JSON.

Example:

// Print arguments as a JSON array.
#include <ccan/json_escape/json_escape.h>

int main(int argc, char *argv[])
{
        printf("[");
        for (int i = 1; i < argc; i++) {
                struct json_escape *e = json_escape(NULL, argv[i]);
                printf("%s\"%s\"", i == 1 ? "" : ",", e->s);
        }
        printf("]\n");
        return 0;
}

License:

BSD-MIT