From the course: Exploring C Libraries

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating JSON output

Creating JSON output - C Tutorial

From the course: Exploring C Libraries

Start my 1-month free trial

Creating JSON output

- [Instructor] As with reading JSON data in the JSON C library, creating JSON data involves using a JSON object variable. In this code, a new JSON object, jdata, is created at line 11. It's empty. No other objects are added, still the object exists, and it can be output which is what happens at line 20. The object is converted to a string and it's output directly to the console. Now I have already compiled and linked the code so let's see what it does. And there's the new object. Not very helpful, but it was created. In this update, a second JSON object is created. The JSON object, jnewobj, is created at line 19, assigned to the strong George Washington. At this point, the code has two JSON objects independent of each other, but at line 30, the json_object_object_add function adds the jnewobj string to the jdata object, assigning it to a keyname, Name. As before, this object is converted to a string, and then…

Contents