json-c / libjson Tutorial with Examples

Posted by Joys of Programming on in C/C++, json-c

JSON is a  data inter-exchange format. When compared to XML, it is very lightweight and more human-readable. The Data representation has some what a similar representation like C/C++ structures. It is nowadays very heavily used data format for data transfer in the web. Most languages like PHP have functions to manipulate JSON data. In case of C/C++, there are many libraries like json-c, json-glibc, jsoncpp.

  1. Introduction to JSON
  2. json-c: Installation
  3. Other libraries: json-glib: Installation
  4. Compiling a json-c program
  5. A simple and Complete Json Parser
  6. Working with json objects: Getting the type and browsing each json object
    1. json_object_get_type: Get Type of a JSON object
    2. json_object_object_foreach : Browse through every json object
    3. json_object_is_type : Check the type of a json_object
  7. Getting the value of a json object
    1. Boolean: json_object_get_boolean : Get boolean value of a json object
    2. Integers: json_object_get_int : Get integer value of a json object
    3. Strings: json_object_get_string : Get string value of a json object
  8. Creating a new json object: Integers, Booleans, Strings
    1. Json: json_object_new_object : Creating a new json object
    2. Integers: json_object_new_int: Creating an integer json object
    3. Booleans: json_object_new_boolean: Creating a boolean json object
    4. Strings: json_object_new_string: Creating a stringjson object
    5. Double(Floating Point Numbers): json_object_new_double: Creating a double json object
    6. Arrays: json_object_new_array: Creating an array json object
  9. Working with arrays
    1. Adding a json object to an array: json_object_array_add
    2. Adding a json object to an array at specified index: json_object_array_put_idx

Hope you found this tutorial useful. Please leave your valuable comments.

Tags: , , ,

Comments:

1 Comment

  • GenericProgrammer says:

    Could really use a tutorial on how to get things by the key. Say I named a key SuperPower. I want to find wherever SuperPower is inside of my object and then return that value.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.