Understanding JSON

Many of our connectors send your interactions in batches that consist of multiple JSON objects. It's important to understand the way that these are formatted. Let's start by considering a simple case, a JSON object containing a blog entry:

{
    "blog":{
        "created_at":"Thu,
         16 Feb 2012 03:10:00 +0000",
        "id":"1e1584bb62cba400e061efcafb08a32a",
        "author":{
            "name":"Stewart",
            "link":"http://www.datasift.com"
        },
        "content":"<p>On Wednesday we will be launching DataSift. This is a massive moment for myself with four years invested in getting to this point and I cannot wait for everyone to be finally able to use the platform. As well as the launch I am announcing today that I am happily handing over the role of CEO to Rob Bailey (you can later read the official company statement) -&nbsp;I will move into the CTO role which&nbsp;will allow me focus all of my time on the technical vision and evangelizing the platform.</p>",
        "title":"My Next Steps",
        "link":"http://www.nickhalstead.com/my-next-steps",
        "contenttype":""
    }
}

At the highest level, this content is wrapped in curly braces; inside, there are sets of key-value pairs, with further nesting as needed.

Here's another single JSON object, a really simple one this time. It simply tells us that the value of A is 1:

{
    "A": 1
}

This object contains just one key-value pair but it's still valid JSON. Now, suppose that your connector needs to send two objects like this in a batch. It wraps them in square brackets and separates them with commas:

[
    {
        "A": 1
    },
    {
        "B": 2
    }
]

Once DataSift has delivered the objects, it's important that your code can parse the JSON, stripping out the square brackets and recognizing the commas between the objects.