json_object_new_int- Create a new Integer json object
json_object_new_int is used to create a new integer json object. The syntax of the function is As you can see, it returns a pointer to the json object The following program shows the usage of the function The output of the program is something like this
json_object_new_object: Creating a new Json object
json_object_new_object is used to create a new json object. Once you create a json object, you can add more objects to it. The syntax of the function is As you can see, it returns a pointer to the json object The following program shows the usage of the function The output of the program is [...]
json_object_is_type: Check the type of json object
json_object_is_type is used to check whether the type of the json object is same as that of the specified type. So you can easily guess that the function takes two arguments The output of the program is something like this The input to the program is
json_object_object_get: Get a json object
json_object_object_get() is used to get the json object. JSON contains key:value pairs. The value can be an array, integer, boolean, double. It can also be a json object. That means to access the values within the json object, we must recursively go through json objects. The following program shows this Let’s compile the program. If [...]
json_object_get_boolean : Get boolean value of a json object
json_object_get_boolean() function is used to get the boolean value of a json object. The syntax It takes json_object as a parameter and returns back an boolean. The following program demonstrates this. the function json_parse accepts a json_object with one or more key:boolean pairs. Let’s compile the program. If you fail any compilation issues, refer the [...]
json_object_object_foreach : Browse through every json object
You can browse through every json object using the macro json_object_object_foreach The syntax where obj is the json object you want to parse, key and value correspond to key: value pairs. As mentioned before, json_object_object_foreach is a macro defined something like this So key, val are not some variables, but you can choose any random [...]
Compiling a json-c program in Linux
If you have installed json-c in your machine, let’s experiment with a simple JSON program making use of JSON-C functions Let’s name the above file as json_type.c. Let’s compile it As you see, there are errors. To compile the program, we must use the “-l” option with the library name “json“. This helps in dynamic [...]