cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Mobutu1650
Frequent Visitor

Append to Array or Add Property?

Hello,

 

I am trying to generate an object array with a single object called New Order with sub-array of properties, like so:

 

{
"NewOrder": [
{
"SKU":"123456",

"Brand":"SP",

"Disciount":"5",

}
]
}

 

I have the following two scenarios:

 

a) 

Mobutu1650_0-1656966684469.png

Mobutu1650_1-1656966712961.png

 

which provides the following output:

 

[
  {
    "SKU""123456"
  },
  {
    "Brand""SP"
  },
  {
    "Discount""5"
  }
]
 
or Scenario B:
 
Mobutu1650_0-1656966684469.png

 

Mobutu1650_2-1656967198586.png

 

Which gives me the following output:

 

[
  "\"SKU\": \"123456\"",
  "\"Brand\": \"SP\"",
  "\"Customer Discount\": \"5\""
]

 

2 REPLIES 2
eliotcole
Super User
Super User

When creating objects it not impossible to do it inside the object or array variable, but it's just a bit annoying as you mostly have to force it using the json() function inside an expression.

 

Here I think that your easiest solution (if you need it in an object) is to just construct the object inside a Compose action, then call the compose action inside an object variable.

 

If you're performing these actions inside an Apply to each action, then:

  1. Make the Array variable before the Apply to each
  2. Have a Compose action inside the Apply to each which is appended to the array too
  3. Then, after the Apply to each have an action to create the object and have the "NewOrder" key with the value of your array variable.

 

Hope that this helps, @Mobutu1650.

Thanks @eliotcole. In theory would it be easier to just have it as a plain array without the need for an object container like so:

 

{"SKU": "123456",

"BRAND": "SP",

"DISCOUNT": "5",

}

 

 

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (1,992)