Browse Source Download (without any required ccan dependencies)
json_escape
Escape sequences for JSON strings
Rusty Russell <[email protected]>
This code helps you format strings into forms useful for JSON.
// 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;
}
BSD-MIT