1 /* 2 * JSON parser - test program 3 * Copyright (c) 2019, Jouni Malinen <j@w1.fi> 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9 #include "utils/includes.h" 10 #include "utils/os.h" 11 #include "utils/json.h" 12 13 main(int argc,char * argv[])14int main(int argc, char *argv[]) 15 { 16 char *buf; 17 size_t len; 18 struct json_token *root; 19 20 if (argc < 2) 21 return -1; 22 23 buf = os_readfile(argv[1], &len); 24 if (!buf) 25 return -1; 26 27 root = json_parse(buf, len); 28 os_free(buf); 29 if (root) { 30 size_t buflen = 10000; 31 32 buf = os_zalloc(buflen); 33 if (buf) { 34 json_print_tree(root, buf, buflen); 35 printf("%s\n", buf); 36 os_free(buf); 37 } 38 json_free(root); 39 } else { 40 printf("JSON parsing failed\n"); 41 } 42 43 return 0; 44 } 45