-
Notifications
You must be signed in to change notification settings - Fork 4
/
json_output.c
60 lines (52 loc) · 845 Bytes
/
json_output.c
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
48
49
50
51
52
53
54
55
56
57
58
59
#include "server.h"
static bool g_open_brace = false;
static bool g_first_node = true;
static bool g_first_child = true;
void
json_close_previous()
{
if (g_open_brace) {
printf("}");
}
g_open_brace = false;
}
void
json_start()
{
printf("{");
}
void
json_end()
{
json_close_previous();
printf("}\n");
}
void
json_node(char *name)
{
json_close_previous();
if (!g_first_node) {
printf(", ");
}
g_first_node = false;
g_first_child = true;
printf("\"%s\": ", name);
}
void
json_text(char *text)
{
printf("\"%s\"", text);
}
void
json_child_node(char *name, char *text)
{
if (!g_open_brace) {
printf("{");
}
g_open_brace = true;
if (!g_first_child) {
printf(", ");
}
g_first_child = false;
printf("\"%s\": \"%s\"", name, text);
}