AnsweredAssumed Answered

Parsing/Mapping JSON profile to XML Response Profile

Question asked by ErikIvarsson3431 on Oct 8, 2015
Latest reply on Aug 22, 2018 by kartikay.nagal147205

Hi,
I am consuming a web service that returns json data in the following format:

{
   "DataFields":    [
            {
         "FieldName": "NameOfField",
         "GroupKeyName": "Key",
         "LookupValue": null,
         "Value": "ValueToUse"
      },
            {
         "FieldName": "NameOfField",
         "GroupKeyName": "Key",
         "LookupValue": null,
         "Value": "ValueToUse"
      },
**** About 100 objects, same format ****
   ],
   "Message": "",
   "Success": true
}
I have imported a json profile containing an example response and i generated a response profile, this one holds an array of these "objects". In the end of the process I want to be able to map this to a XML response profile to return.
What I need is to know how to handle the json response, I know that I can parse the Json string in javascript for example but I do not understand how I can get the response to a regular json string. Or if there is some way that I can map in other way, what I thought I could to was something similar to this scripting function:

var obj = JSON.parse(jsonInputText);

for(var i = 0; i <= obj.DataFields.length; i++){
     if(obj.DataFields[i].FieldName == "value1"){
          value1 = obj.Value;
     }else if(obj.DataFields[i].FieldName == "value2"){
         value2 = obj.Value;
     }
}
Where jsonInputText would be the JSON String, the value1 be the output element of the function for the value1 parameter. This soultion would require x numbers of if/else statements and just seems sloppy. And it also requires I am able to retrieve the acctual JSON String.

 

Does anyone have experience in working with similar responses and parsing it before they are returned to a user/third party software?

Outcomes