Split JSON array response - Need quick help!!

How to iterate the below. Currently I am using Extract Variable and Assign Message in the response, but I am getting the output in an array like the below.

"ID": "["0013z00002OUKlNAAX","0013z00002OUKlLAAX","0013z00002OUKlMAAX"]

Expected:

{"ID": "0013z00002OUKlNAAX"} {"ID": "0013z00002OUKlLAAX"}
0 5 1,528
5 REPLIES 5

@Dino-at-Google @Dino Thought you can help 🙂 Many thanks.

#1 What does the original input message look like?

It seems You have described

  • what you actually are getting
  • what you want to get

But you haven't described the input data shape.

I can tell you how to transform from what you're actually getting to what you want to get, but that might not be the most efficient way to get from what you originally have to what you want to get. There might be a more direct way.

#2

The thing you want to get is not valid self-standing JSON. I guess you want that to appear in an array. Can you provide more context?

Many thanks for your response. Below is my SFDC response.

{"totalSize":12,"records":[{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlNAAX"},"Id":"0013z00002OUKlNAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlLAAX"},"Id":"0013z00002OUKlLAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlMAAX"},"Id":"0013z00002OUKlMAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlDAAX"},"Id":"0013z00002OUKlDAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlEAAX"},"Id":"0013z00002OUKlEAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlFAAX"},"Id":"0013z00002OUKlFAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlGAAX"},"Id":"0013z00002OUKlGAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlHAAX"},"Id":"0013z00002OUKlHAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlJAAX"},"Id":"0013z00002OUKlJAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlKAAX"},"Id":"0013z00002OUKlKAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlIAAX"},"Id":"0013z00002OUKlIAAX"},{"attributes":{"type":"Account","url":"/services/data/v42.0/sobjects/Account/0013z00002OUKlOAAX"},"Id":"0013z00002OUKlOAAX"}],"done":true}

==

I am trying to retrieve all Id and map to the JSON response schema. In the output, I need the Id result to be split, as each Id will have modified date for ex. to be mapped (but I can sort the additional mappings I think).

Please let me know if you need any more details. Thanks.

I guess you used ExtractVariables with a JSONPath?

I'm not clear on exactly the shape you desire for the output.

Given this input json

{ "ID": ["A","B","C"] }

Then, with this JavaScript,

var input = JSON.parse(context.getVariable('input')); 
var output = [];
input.ID.forEach(function(s) { output.push({ID:s})});


I can get this into the output:

[{"ID":"A"},{"ID":"B"},{"ID":"C"}]