summaryrefslogtreecommitdiff
path: root/src/examples/jsontest/jsontest.c
blob: 4237ed2413b605afc139de4188766a9510eca477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <libmowgli-2/mowgli.h>

void
out_string(mowgli_json_output_t *out, const char *str, size_t len)
{
	fwrite(str, 1, len, stdout);
}

void
out_char(mowgli_json_output_t *out, const char c)
{
	fputc(c, stdout);
}

mowgli_json_output_t out =
{
	.append = out_string,
	.append_char = out_char,
};

int
main(int argc, char *argv[])
{
	int i;
	mowgli_json_t *n;

	if (argc < 2)
	{
		printf("Usage: %s file [file ...]\n", argv[0]);
		return 1;
	}

	for (i = 1; i < argc; i++)
	{
		n = mowgli_json_parse_file(argv[i]);

		if (n != NULL)
		{
			mowgli_json_serialize(n, &out, 1);
			putchar('\n');
		}

		mowgli_json_decref(n);
	}

	return 0;
}