cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MStoltzfus
Regular Visitor

How to Create a single JSON object from an Array of Objects?

Currently setting up a form that sends submission data in through an awkwardly formatted JSON array. I've been able to use the "select" operation to pair the keys and values the way I want to, but am hitting a wall in terms of knowing how to convert the array that it gives me into a single JSON object containing multiple name/value pairs.

 

 

[
    {
      "Company Name": "ContosoLatoso LLC"
    },
    {
      "First Name": "John"
    },
    {
      "Last Name": "Smith"
    },
    {
      "Email Address": "test@contosolatoso.com"
    },
    {
      "Country": "USA"
    },
    {
      "Type of Company": "Organization using Microsoft 365"
    },
    {
      "How many users need this functionality?": "300"
    },
    {
      "Explain your need for this functionality": "We need it badly"
    },
    {
      "Top features & functionality you think should be included in the product": "We want it muchly"
    },
    {
      "Other Questions": "How much will it cost?"
    }
  ]

 

I would like to take the data from that array and format it into a single JSON object as demonstrated below...

 

{
   "Company Name": "ContosoLatoso LLC",
   "First Name": "John",
   "Last Name": "Smith",
   "Email Address": "test@contosolatoso.com"
//...And so on and so forth for all the objects from the array above...
}

 

 

Any input on how to go about doing this would be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
v-litu-msft
Community Support
Community Support

Hi @MStoltzfus,

 

Firstly, you could use string() function to convert the array into a string.

Then use replace() function to remove "{" and "}", then use "{" instead of "[" and use "]" instead of "}", then use json() function convert string back to json format:

json(replace(replace(replace(replace(outputs('Compose_2'),'{',''),'}',''),'[','{'),']','}'))

Screenshot 2020-10-22 112548.jpgScreenshot 2020-10-22 112503.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-litu-msft
Community Support
Community Support

Hi @MStoltzfus,

 

Firstly, you could use string() function to convert the array into a string.

Then use replace() function to remove "{" and "}", then use "{" instead of "[" and use "]" instead of "}", then use json() function convert string back to json format:

json(replace(replace(replace(replace(outputs('Compose_2'),'{',''),'}',''),'[','{'),']','}'))

Screenshot 2020-10-22 112548.jpgScreenshot 2020-10-22 112503.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

@v-litu-msft This did the trick, and without any extra init/set variable stuff that had been suggested to me! Thanks!

Helpful resources

Announcements
2022 Release Wave 1 760x460.png

2022 Release Wave 1 Plan

Power Platform release plan for the 2022 release wave 1 describes all new features releasing from April 2022 through September 2022.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,678)