Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Flat Response from JSON

How do I get a flat response as output instead of JSON array

Solved Solved
0 3 141
1 ACCEPTED SOLUTION

the response should be plain text? 

You can use a JS Callout to do that. The JS looks like this: 

var input = JSON.parse(context.getVariable('response.content'));
var output =
  "EmployeeRoleType: " + input.organisation.employee.role.type + '\n' +
  "Employee Name: " + input.organisation.employee.name + '\n' +
  "EmployeeDept: " + input.organisation.employee.department + '\n';

context.setVariable('response.header.content-type', 'text/plain');
context.setVariable('response.content', output);

 

View solution in original post

3 REPLIES 3

😁

I  need more explanation to have a chance of guessing what you mean by "flat response".  

How about showing an example of what you want?

the output response should not be in the form of an array. 

{

'organisation' : {

                    'employee': {

                                      'role': {

                                               'type': 'manager',

                                          }

                                  'name': 'abc',

                                  'department': 'xyz'

                             }

               }

}

Instead of this JSON Array the response should be

EmployeeRoleType: Manager

Employee Name: abc

EmployeeDept: xyz

the response should be plain text? 

You can use a JS Callout to do that. The JS looks like this: 

var input = JSON.parse(context.getVariable('response.content'));
var output =
  "EmployeeRoleType: " + input.organisation.employee.role.type + '\n' +
  "Employee Name: " + input.organisation.employee.name + '\n' +
  "EmployeeDept: " + input.organisation.employee.department + '\n';

context.setVariable('response.header.content-type', 'text/plain');
context.setVariable('response.content', output);