Configure JSON Tool Based On Returned JSON Data Structure

Introduction

In this tutorial, you will learn how to configure the JSON Tool in Joget based on different returned JSON data structures. This guide will walk you through handling simple and complex JSON data, ensuring your Joget application can process and integrate various JSON formats effectively.

Note

To follow this tutorial, please head to jsonCurrency.zip the attached .txt files and save them in the ROOT folder of your local Joget Installation. You can find the ROOT folder by navigating to your installation folder > apache-tomcat-8.5.72 > webapps > ROOT.

How does it work?

The JSON Tool allows you to call external APIs and integrate their responses into your Joget application. Depending on the structure of the JSON data returned, you will need to configure the JSON Tool differently.

For example, if the JSON data contains an object (denoted by curly brackets {}), you can extract specific fields directly. However, if the JSON data contains an array (denoted by square brackets []), you must configure the tool to iterate through the array and create multiple records.

Here’s a step-by-step guide to configuring the JSON Tool based on different JSON structures.

  • Example 1: Simple JSON Object
    If your JSON data looks like this (returned from http://localhost:8080/jsonCurrency1.txt):
    {
      "base": "SGD",
      "date": "2022-09-14",
      "rates": {
        "USD": 0.711805
      },
      "success": true,
      "timestamp": 1663170544
    }

    Since there is no array to iterate through, the configuration will only create a single record based on the available data.

  • Example 2: JSON Array
    If your JSON data looks like this (returned from http://localhost:8080/jsonCurrency2.txt):
    {
        "base": "SGD",
        "date": "2015-12-21",
        "rates": [
            { "currency" : "AUD",
              "rate" : 0.99092
            },
            { "currency" : "BGN",
              "rate" : 1.2777
            },
            { "currency" : "BRL",
              "rate" : 2.8235
            }
        ]
    }

    Here, you will use the Base JSON Object Name for Multirow Data feature to iterate through the rates array and create multiple records for each currency and rate pair.

Related documentation

Created by Julieth Last modified by Aadrian on Dec 13, 2024