2 * Display directory contents
9 #include <zzjson/zzjson.h>
12 static void myerror(void *ehandle
, const char *format
, ...) {
14 fprintf(ehandle
, "error: ");
16 vfprintf(ehandle
, format
, ap
);
22 int main(int argc
, char *argv
[])
26 openconsole(&dev_rawcon_r
, &dev_stdcon_w
);
29 openconsole(&dev_rawcon_r
, &dev_ansiserial_w
);
34 ZZJSON_CONFIG config
= { ZZJSON_VERY_STRICT
, NULL
,
35 (int(*)(void*)) fgetc
,
37 malloc
, calloc
, free
, realloc
,
38 stderr
, myerror
, stdout
,
39 (int(*)(void*,const char*,...)) fprintf
,
40 (int(*)(int,void*)) fputc
};
45 tmp
= zzjson_create_array(&config
,
46 zzjson_create_number_d(&config
, 3.14),
47 zzjson_create_number_i(&config
, 1234LL),
48 zzjson_create_number_i(&config
, -4321LL),
49 zzjson_create_true(&config
),
50 zzjson_create_false(&config
),
51 zzjson_create_null(&config
),
52 zzjson_create_string(&config
, "hello, world"),
53 zzjson_create_object(&config
,
54 "picard", zzjson_create_string(&config
, "jean-luc"),
55 "riker", zzjson_create_string(&config
, "william t."),
57 zzjson_create_object(&config
, NULL
),
58 zzjson_create_array(&config
, NULL
),
62 fprintf(stderr
, "error during creation of json tree\n");
66 tmp2
= zzjson_array_prepend(&config
, tmp
,
67 zzjson_create_string(&config
, "prepended string"));
70 fprintf(stderr
, "error during prepend\n");
75 tmp2
= zzjson_array_append(&config
, tmp
,
76 zzjson_create_string(&config
, "appended string (slow)"));
79 fprintf(stderr
, "error during append\n");
84 zzjson_print(&config
, tmp
);
86 if (tmp
) zzjson_free(&config
, tmp
);
89 tmp
= zzjson_create_array(&config
, NULL
); /* empty array */
90 tmp
= zzjson_array_prepend(&config
, tmp
, zzjson_create_true(&config
));
91 zzjson_print(&config
, tmp
);
92 zzjson_free(&config
, tmp
);
96 tmp
= zzjson_create_object(&config
, NULL
); /* empty object */
97 tmp
= zzjson_object_prepend(&config
, tmp
, "hello",
98 zzjson_create_string(&config
, "world"));
99 tmp
= zzjson_object_append(&config
, tmp
, "goodbye",
100 zzjson_create_string(&config
, "cruel world"));
101 zzjson_print(&config
, tmp
);
102 zzjson_free(&config
, tmp
);