Source Code File 10-02_jsonoutput
10-02_jsonoutput.c
#include <stdio.h> #include <stdlib.h> #include <json-c/json.h> int main() { const char filename[] = "sample.json"; json_object *jdata; const char *jstring; jdata = json_object_from_file(filename); if( jdata==NULL ) { fprintf(stderr,"Unable to process %s\n",filename); exit(1); } jstring = json_object_to_json_string(jdata); puts(jstring); return(0); }
Output
{ "firstName": "Simon", "middleName": "Bar", "lastName": "Sinister", "address": { "street": "123 Evil Ave.", "city": "Bigtown", "state": "New York", "zip": "12345" }, "isCartoon": true, "IQ": 213.5, "phones": [ { "type": "lab", "number": "212 555-1234" }, { "type": "mobile", "number": "868 555-1234" } ], "assistant": "Cad Lackey", "spouse": null, "favorite numbers": [ 2, 13, 23, 66 ] }
Copyright © 1997-2024 by QPBC.
All rights reserved