2 * UCW JSON Library -- Tests
4 * (c) 2015 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
11 #include <ucw/fastbuf.h>
13 #include <ucw/trans.h>
14 #include <ucw-json/json.h>
18 static int opt_escape;
19 static int opt_indent;
21 static struct opt_section options = {
23 OPT_HELP("Test program for UCW JSON library."),
24 OPT_HELP("Usage: json-test [options]"),
28 OPT_BOOL('r', "read", opt_read, 0, "\tRead JSON from standard input"),
29 OPT_BOOL('w', "write", opt_write, 0, "\tWrite JSON to standard output"),
30 OPT_BOOL('e', "escape", opt_escape, 0, "\tEscape non-ASCII characters in strings"),
31 OPT_BOOL('i', "indent", opt_indent, 0, "\tIndent output"),
36 int main(int argc UNUSED, char **argv)
38 opt_parse(&options, argv+1);
40 struct json_context *js = json_new();
41 struct json_node *n = NULL;
44 js->format_options |= JSON_FORMAT_ESCAPE_NONASCII;
46 js->format_options |= JSON_FORMAT_INDENT;
50 struct fastbuf *fb = bfdopen_shared(0, 65536);
53 n = json_parse(js, fb);
57 fprintf(stderr, "ERROR: %s\n", x->msg);
66 n = json_new_number(js, 42);
71 struct fastbuf *fb = bfdopen_shared(1, 65536);
72 json_write(js, fb, n);