The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Parsing REST Output for Data Stream Action

victor21
Tera Guru

Hello Listers,

How can I parse (splitter and script parser steps) the following REST output to be able to use it in Data Stream Action/IntegrationHub?

{
    "data": {
        "viewer": {
            "account": {
                "services": [
                    {
                        "serviceId": "svc01",
                        "serviceName": "svc01 Name"
                    },
                    {
                        "serviceId": "svc02",
                        "serviceName": "svc02 Name"
                    }
				]
            }
        }
    }
}

I am mainly interested in the "services" section - everything I tried so far is giving me "Internal Server Error" though the REST step executed successfully.

Thanks for any suggestion in the right direction.

 

Regards,

Victor

1 ACCEPTED SOLUTION

Hi Bhimashankar H,

Thanks for your response.

In the Script Splitter step, there is no "response" argument. I have tried using "$.data.viewer.account.services" for splitter step and the scriptlet 

(function parse(inputs, outputs) {
var item = JSON.parse(inputs.sourceItem);
outputs.targetObject = item;
//tried also outputs.targetObject = item.data.viewer.account.services
})(inputs, outputs);

for script parser step - but I kept on receiving "Internal Server Error"

 

Thanks,

Victor

View solution in original post

3 REPLIES 3

Bhimashankar H
Mega Sage

Hi @victor21 ,

 

To parse the "services" array from this REST output and use it in Data Stream Actions / IntegrationHub, you should use the Script Parser step in your Data Stream definition. The Script Parser extract, transform, and output only the desired part of the response. It will show then ServiceId and Name to map.

 

(function transform(response) {
    return response.data.viewer.account.services;
})(parsedResponse);

 

This will pass only the list of service objects for mapping.

 

Using Splitter step:

You set the Splitter JSON Path as data.viewer.account.services if you want each service object to be split as an individual record for the subsequent Action steps.

 

Thanks,
Bhimashankar H

 

-------------------------------------------------------------------------------------------------
If my response points you in the right directions, please consider marking it as 'Helpful' & 'Correct'. Thanks!

Hi Bhimashankar H,

Thanks for your response.

In the Script Splitter step, there is no "response" argument. I have tried using "$.data.viewer.account.services" for splitter step and the scriptlet 

(function parse(inputs, outputs) {
var item = JSON.parse(inputs.sourceItem);
outputs.targetObject = item;
//tried also outputs.targetObject = item.data.viewer.account.services
})(inputs, outputs);

for script parser step - but I kept on receiving "Internal Server Error"

 

Thanks,

Victor

Hi,

Sorry for the confusion - the setting was correct the issue was the output variable that was not set.

Regards,

Victor