Creating and storing Json array with a for each loop to be able to post

Scenario - I have arrays that I would like to store in a json array to be able to post.

Array values can be seen in image attached. I have a set of companyids in an array, the number of companyids may not always be two. So with a for each activity based on the number of companyids this will determine the iteration count. The issue I’m facing is that with after every iteration the previous values are overridden. Is there a way to store the value so the final json array looks like the below image. I’ve attached images of array values, activities and the intended output for json array.

Any advice is welcome.

Img 1 Array & values

img 2/3 activities used

img 4 current output

img 5 intended output

Hi @duaine.b ,

The reason JArray values getting replaced is you need to append Jarray values into a list before adding them into “InsuredCompanyInfo” key.

I tried a backtracking approach, refer attached. Here I created your expected post Json object quick and fast with respective to CompanyId array’s length using for each and (4.2 KB)

If you find this as works for you, mark it as solution.
Happy Automating :smile: