Defining JSON Array - Single Record

Situation:

We have a JSON Array that contains a single record. The record level data is generated using the JSON schema, but the array isn't defined properly with the brackets []

 

Expected

{
   "items": [
      {
         "description": {},
         "account": {
            "project": 0,
            "line": 0,
            "location": 123,
            "account": 12354,
            "center": 1234,
            "channel": 0,
            "code": 1
         },
         "group": {},
         "name": {},
         "amount": {
            "value": 1234,
            "unit": "USD"
         },
         "CompanyID": {}
      }
   ]
}

 

Actual

{
   "items": [
      {
         "description": {},
         "account": {
            "project": 0,
            "line": 0,
            "location": 123,
            "account": 12354,
            "center": 1234,
            "channel": 0,
            "code": 1
         },
         "group": {},
         "name": {},
         "amount": {
            "value": 1234,
            "unit": "USD"
         },
         "CompanyID": {}
      }
   }

Solution:

  1. Extract the attached file “XMLtoJSON.zip” and place the “XMLtoJSON.class” 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 comma for which you want the corresponding values to be treated as an array while creating the JSON file. In the above example, the key would be items

  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.