Defining JSON Array for single or multiple records

Situation:

We need to define JSON output as an Array that contains brackets [] whether it is a single record or multiple records. While using JSON schema, we have JSON as an array at output only for multiple records at source end. When we have some specific scenario where we need Array for single record then we need to use custom class approach.

 

Expected

For Single Record :

{

    "casetype_id":"abcdef-2dc5-4442-b636",

    "requestor":{

        "id":{

            "kvk_number":123456789,

            "branch_number":""

        },

        "type":"company"

    },

    "source":"webformulier",

    "values":{

        "ztc_locatie":[123],

        "ztc_locatie_omschrijving":[570]

    }

}

 

For Multiple Record :

{

    "casetype_id":"abcdef-2dc5-4442-b636",

    "requestor":{

        "id":{

            "kvk_number":123456789,

            "branch_number":""

        },

        "type":"company"

    },

    "source":"webformulier",

    "values":{

        "ztc_locatie":[123,456,789],

        "ztc_locatie_omschrijving":[570,571,572]

    }

}

 

Solution:

  1. Download the attached file “XMLtoJSON.class” and place the file in the /ServerKernel/customClasses folder. Restart the Adeptia Server.

     2. Create a custom plugin activity and copy the code below:

          String keys = "key1,key2";

          new XMLtoJSON().convertData(keys,inputStream,service);

Define the list of keys separated by the comma for which you want the corresponding values to be treated as an array while creating the JSON file. As an example in our use case, Keys would be the items as shown below:-

              String keys = "ztc_locatie,ztc_locatie_omschrijving";

  1. In process flow remove JSON schema after the mapping activity and place Custom Plugin activity created in step 2. Make sure that stream name is "default" in the Multiple Stream coming from custom plugin to the JSON target activity.

  1. Execute the process flow

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.