--- libelwix/example/test_valid.c 2025/08/21 16:08:20 1.1 +++ libelwix/example/test_valid.c 2025/08/25 13:00:37 1.2 @@ -0,0 +1,36 @@ +#include +#include + + +int +main(int argc, char **argv) +{ + int pos = 0, started = 0; + char line[BUFSIZ] = { 0 }, str[BUFSIZ] = { 0 }, str2[BUFSIZ]; + json_t json; + + if (argc > 1) { + printf("validate=%d\n", json_validate(argv[1], &started)); + printf("started=%d\n", started); + } + + printf("Input test JSON for marshaling> "); + while (!feof(stdin)) { + fgets(line, sizeof line - 1, stdin); + strlcat(str, line, sizeof str); + + if (json_validate(str, &started)) + break; + } + strlcpy(str2, str, sizeof str2); + + json_init(&json, 0); + printf("json_parse num tokens=%d\n", json_parse(&json, str, sizeof str, NULL, 0)); + json_free(&json); + + if (json_marshaling(str, 0)) + printf("Marshaled JSON with spaces> %s\n", str); + if (json_marshaling(str2, 1)) + printf("Marshaled JSON> %s\n", str2); + return 0; +}