Twitter LogoFacebook Logo
Converting the Response into a JSON Object
Learn how to convert the Response String into a JSON object to extra data from it.
By: King

Hello, in this tutorial, I will show you how to convert the Response String into a JSON object so you can extract contents from it in the blueprint.

Converting the Response into a JSON

To convert the Response String from the Make a HTTP Request node into a JSON object, make sure that the string is a JSON object.

Image from Codeible.com

Use the To JSON node and connect the Response String.

Image from Codeible.com

It returns a JSON object that we can then use any of these Get Nodes to get the data from the object.

Image from Codeible.com

Extracting the contents

Take a look at the example JSON string from the response:

{
   "purchaseToken":"some-token-value",
   "orderId":"abc123",
   "purchaseTime":"6",
   "isValid":false
}

The purchaseToken and orderId is a string, the purchaseTime time is most likely a number, and isValid is a boolean.

To get the purchaseToken or orderId, use the Get String node.

Image from Codeible.com

For the purchaseTime, use Get Number.

Image from Codeible.com

For the boolean, use Get Boolean.

Image from Codeible.com

Nested JSONs

Sometimes your JSON object may contain another JSON or an array of them like this:

{
   "purchaseToken":"some-token-value",
   "orderId":"abc123",
   "purchaseTime":"6",
   "isValid":false,
   "contacts": [
       {
           "name": "Codeible",
            "email": "Codeible@ccodeible.com"
        },
        {
           "name": "King",
           "email": "Codeible@ccodeible.com"
        }
   ]
}

To get them, use the Get Object or the Get Object Array nodes.

Image from Codeible.com

The contacts property is an array of JSON objects, so we need to use the Get Object Array node.

Image from Codeible.com

Once we have the array, we can use the For Each Loop node to iterate through all the ojbects.

Image from Codeible.com

The Array Element from the loop represents the JSON objects. We can then use the Get nodes to get the data from it.

Image from Codeible.com

Sign In