cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Trying to extract JSON array info

Hi all,

 

I am trying to extract certain information from a JSON array (that is provided via a webhook). Basically its a user onboarding through a platform that is then trying to run a flow to put the required info into a SharePoint list. The trouble i am having is getting the required info (user first name, last name, mobile etc...) into usable variables.

 

My flow works like this:

 

1. HTTP request received

2. Initialize variable

3. Select

 

david_ashworth_0-1627519670099.png

 

david_ashworth_1-1627519692987.png

 

david_ashworth_2-1627519711422.png

 

This is what i get out

 

david_ashworth_3-1627519748063.png

 

I have assigned a JSON ID field in the originating app to easily identify each response

 

[
  {
    "Id""first101",
    "Label""First",
    "Value""Bob"
  },
  {
    "Id""last102",
    "Label""Last",
    "Value""Smith"
  },
  {
    "Id""title103",
    "Label""Job Title",
    "Value""nothing"
  },
  {
    "Id""mobile104",
    "Label""Mobile Phone Number",
    "Value""0123456789"
 
 
So this is where i get stuck, how do i pull out those question responses to then create a SharePoint list?
 
Appreciate any help.
 
Thanks,
David
1 ACCEPTED SOLUTION

Accepted Solutions
ekarim2020
Super User
Super User

Here is one possible solution for you. It works by taking the original JSON array data, transforming it into a simplified JSON object from which we can easily refer to each JSON property (First name, Last name, Job Title etc):

ekarim2020_5-1627987516734.png

This is the summary of the entire flow which you can create and follow along to determine if this will suit your needs:

ekarim2020_6-1627987718398.png

Starting with the raw JSON data:

ekarim2020_0-1627983895644.png

You can copy and paste the JSON below:

 

[
  {
    "Id": "first101",
    "Label": "First",
    "Value": "Bob"
  },
  {
    "Id": "last102",
    "Label": "Last",
    "Value": "Smith"
  },
  {
    "Id": "title103",
    "Label": "Job Title",
    "Value": "IT Manager"
  },
  {
    "Id": "mobile104",
    "Label": "Mobile Phone",
    "Value": "0123456789"
  }
]

 

Initialise three variables:

ekarim2020_2-1627984190326.png

Use Apply to each to iterate through all the JSON array. We build the a new JSON object, one property at a time in varQuestion. We add a new property to  varQuestion using the addProperty function starting with the first element in the (Compose My JSON) JSON array with ID="first101", then the next element with ID=last102, then title103 and finally mobile104:

ekarim2020_3-1627986206191.png

You can copy and past the following values for the above:

 

@{items('Apply_to_each')['Label']}
@{items('Apply_to_each')['Value']}
@{addProperty(variables('varQuestions'),variables('varLabel'), variables('varValue'))}
@{outputs('String_Property')}

 

We now have a new JSON object in varQuestions and it looks like this:

ekarim2020_0-1627988880785.png

We next add a Compose action using varQuestions as the input so that we can easily reference each property value:

ekarim2020_4-1627986632447.png

The input values for compose can be copied from here:

 

@{variables('varQuestions')}
@{outputs('Compose')['First']}
@{outputs('Compose')['Last']}
@{outputs('Compose')['Job Title']}
@{outputs('Compose')['Mobile Phone']}

 

We reference the properties using the following format:

ekarim2020_1-1627989059184.png

ekarim2020_0-1627990835025.png

And finally, you can add these values to a SharePoint list.

 

Hope this helps.

Ellis

View solution in original post

12 REPLIES 12
ekarim2020
Super User
Super User

What is the structure of the data being returned by Questions? Can you post the structure of the data you are getting?

If you can transform the data into this format:

 

[
  {
    "first": "Bob",
    "lastname": "Smith",
    "Job Title": "nothing",
    "mobile": "0123456789"
  }
]

 

 then you could use Parse JSON to easily refer to each data field:

ekarim2020_0-1627732472729.png

Ellis

Nived_Nambiar
Super User
Super User

Hi @david_ashworth 

There is another way for this too

 

see the workflow 

Nived_Nambiar_0-1627839752173.png

 

 

Here i had intialized the json data [for my demo]

after that i had used Parse JSON Action to parse the data from json data which is stored in Intialise variable action.

Now since there are many items, i used a Apply to each action and inside it i used the following parameters

Nived_Nambiar_1-1627839893061.png

 

 

Here i used body which need to be iterated here.

 

After that i used compose action to get the value of Label key,

 

For that i had used the following expression: 

items('Apply_to_each')?['Label']
 
Now i got the results like this
 
Nived_Nambiar_2-1627840177030.png

 

Nived_Nambiar_3-1627840192440.png

 

 

Like that etc etc..

 

Try this way

 

Mark it as solution if it resolves ur query

 

Regards,

Nived N

 

 

Hi @ekarim2020,

 

This is what i am getting from the HTTP request:

 

SCHEMA:

{
  "type""object",
  "properties": {
    "User": {
      "type""object",
      "properties": {
        "UserEmail": {
          "type""string"
        },
        "UserFirstName": {
          "type""string"
        },
        "UserLastName": {
          "type""string"
        },
        "UserMobile": {
          "type""string"
        },
        "UserPhone": {
          "type""string"
        },
        "UserPsaId": {
          "type""integer"
        },
        "UserOfficeId": {
          "type""string"
        },
        "UserIsAdmin": {
          "type""boolean"
        },
        "UserIsPriority": {
          "type""boolean"
        }
      }
    },
    "Company": {
      "type""object",
      "properties": {
        "CompanyName": {
          "type""string"
        },
        "CompanyPsaId": {
          "type""integer"
        },
        "CompanyTenantId": {
          "type""string"
        }
      }
    },
    "Ticket": {
      "type""object",
      "properties": {
        "TicketId": {
          "type""integer"
        },
        "TicketSubject": {
          "type""string"
        },
        "TicketDescription": {
          "type""string"
        },
        "TicketEstimatedTime": {
          "type""integer"
        },
        "CheckList": {
          "type""string"
        },
        "Script": {
          "type""string"
        },
        "Questions": {
          "type""array",
          "items": {
            "type""object",
            "properties": {
              "Id": {
                "type""string"
              },
              "Label": {
                "type""string"
              },
              "Value": {
                "type""string"
              }
            },
            "required": [
              "Id",
              "Label",
              "Value"
            ]
          }
        }
      }
    },
    "Feedback": {
      "type""object",
      "properties": {
        "FeedbackRating": {
          "type""integer"
        },
        "FeedbackSentiment": {
          "type""integer"
        },
        "FeedbackComment": {
          "type""string"
        },
        "FeedbackPhone": {
          "type""string"
        }
      }
    },
    "Routing": {
      "type""object",
      "properties": {
        "RoutingBoard": {
          "type""string"
        },
        "RoutingStatus": {
          "type""string"
        },
        "RoutingType": {
          "type""string"
        },
        "RoutingSubType": {
          "type""string"
        },
        "RoutingItem": {
          "type""string"
        },
        "RoutingPriority": {
          "type""string"
        },
        "RoutingSource": {
          "type""string"
        },
        "RoutingIsNeedsApproval": {
          "type""boolean"
        }
      }
    },
    "Agent": {
      "type""object",
      "properties": {
        "AgentId": {
          "type""integer"
        },
        "AgentFirstName": {
          "type""string"
        },
        "AgentLastName": {
          "type""string"
        },
        "AgentEmail": {
          "type""string"
        }
      }
    }
  }
}
 
 
And the QUESTIONS returns this:
 
[
  {
    "Id""first101",
    "Label""First",
    "Value""Bob"
  },
  {
    "Id""last102",
    "Label""Last",
    "Value""Smith"
  },
  {
    "Id""title103",
    "Label""Job Title",
    "Value""nothing"
  },
  {
    "Id""mobile104",
    "Label""Mobile Phone Number",
    "Value""0123456789"
  },
  {
    "Id""\"Id\": \"18101\"",
    "Label""Random",
    "Value""C@nberra2021"
  }
]
 
I then try to initialize the variable as type Array and get this value of output:
 
[
  {
    "Id""first101",
    "Label""First",
    "Value""Bob"
  },
  {
    "Id""last102",
    "Label""Last",
    "Value""Smith"
  },
  {
    "Id""title103",
    "Label""Job Title",
    "Value""nothing"
  },
  {
    "Id""mobile104",
    "Label""Mobile Phone Number",
    "Value""0123456789"
  },
  {
    "Id""\"Id\": \"18101\"",
    "Label""Random",
    "Value""P@ssword"
  }
]
 
 
Thanks for your help

Hi @Nived_Nambiar ,

 

So this is what i have in my flow:

 

david_ashworth_0-1627867853199.png

 

david_ashworth_1-1627867876642.png

 

david_ashworth_2-1627867904699.png

 

with Schema:

 

{
    "type""object",
    "properties": {
        "User": {
            "type""object",
            "properties": {
                "UserEmail": {
                    "type""string"
                },
                "UserFirstName": {
                    "type""string"
                },
                "UserLastName": {
                    "type""string"
                },
                "UserMobile": {
                    "type""string"
                },
                "UserPhone": {
                    "type""string"
                },
                "UserPsaId": {
                    "type""integer"
                },
                "UserOfficeId": {
                    "type""string"
                },
                "UserIsAdmin": {
                    "type""boolean"
                },
                "UserIsPriority": {
                    "type""boolean"
                }
            }
        },
        "Company": {
            "type""object",
            "properties": {
                "CompanyName": {
                    "type""string"
                },
                "CompanyPsaId": {
                    "type""integer"
                },
                "CompanyTenantId": {
                    "type""string"
                }
            }
        },
        "Ticket": {
            "type""object",
            "properties": {
                "TicketId": {
                    "type""integer"
                },
                "TicketSubject": {
                    "type""string"
                },
                "TicketDescription": {
                    "type""string"
                },
                "TicketEstimatedTime": {
                    "type""integer"
                },
                "CheckList": {
                    "type""string"
                },
                "Script": {
                    "type""string"
                },
                "Questions": {
                    "type""array",
                    "items": {
                        "type""object",
                        "properties": {
                            "Id": {
                                "type""string"
                            },
                            "Label": {
                                "type""string"
                            },
                            "Value": {
                                "type""string"
                            }
                        },
                        "required": [
                            "Id",
                            "Label",
                            "Value"
                        ]
                    }
                }
            }
        },
        "Feedback": {
            "type""object",
            "properties": {
                "FeedbackRating": {
                    "type""integer"
                },
                "FeedbackSentiment": {
                    "type""integer"
                },
                "FeedbackComment": {
                    "type""string"
                },
                "FeedbackPhone": {
                    "type""string"
                }
            }
        },
        "Routing": {
            "type""object",
            "properties": {
                "RoutingBoard": {
                    "type""string"
                },
                "RoutingStatus": {
                    "type""string"
                },
                "RoutingType": {
                    "type""string"
                },
                "RoutingSubType": {
                    "type""string"
                },
                "RoutingItem": {
                    "type""string"
                },
                "RoutingPriority": {
                    "type""string"
                },
                "RoutingSource": {
                    "type""string"
                },
                "RoutingIsNeedsApproval": {
                    "type""boolean"
                }
            }
        },
        "Agent": {
            "type""object",
            "properties": {
                "AgentId": {
                    "type""integer"
                },
                "AgentFirstName": {
                    "type""string"
                },
                "AgentLastName": {
                    "type""string"
                },
                "AgentEmail": {
                    "type""string"
                }
            }
        }
    }
}
 
david_ashworth_3-1627867949564.png

 

but the error i get is this:

 

david_ashworth_4-1627867992429.png

 

Thanks for your help on this

Nived_Nambiar
Super User
Super User

Hi @david_ashworth 

 

In the schema section can u generate the schema corresponding to the question http json response?

 

 

Hi @Nived_Nambiar ,

 

Sorry but my understanding of JSON is not great. So you mean the schema under the Parse section?

 

I have entered it like this:

 

david_ashworth_0-1627877213067.png

 

With the Schema:

 

{
    {
        {
            {
                },
                "Questions": {
                    "type""array",
                    "items": {
                        "type""object",
                        "properties": {
                            "Id": {
                                "type""string"
                            },
                            "Label": {
                                "type""string"
                            },
                            "Value": {
                                "type""string"
                            }
                        },
                        "required": [
                            "Id",
                            "Label",
                            "Value"
                        ]
                    }
                }
            }
        }
    },
}
 
But it says this is invalid? I have incorrectly formatted it but not sure where
 
Thanks
Nived_Nambiar
Super User
Super User

Hi @david_ashworth 

You can create the schema from sample json which u showed us as example, just click on that Generate Schema from sample and then add the json u had and then it automatically schema for you!!

 

Regards,

Nived N

Hi @Nived_Nambiar ,

 

Sorry but im not sure i fully understand what you are suggesting. So i have used the sample JSON and entered it into the PARSE action but the error is "ValidationFailed. The schema validation failed." And then under outputs the error states:

 

[
  {
    "message""Invalid type. Expected Object but got Array.",
    "lineNumber"0,
    "linePosition"0,
    "path""",
    "schemaId""#",
    "errorType""type",
    "childErrors": []
  }
]
 
When editing the PARSE JSON Flow, under sample schema i am putting this in (is this correct? If not could you please advise what text i need to put in?):
 
{
  "type""object",
  "properties": {
    "User": {
      "type""object",
      "properties": {
        "UserEmail": {
          "type""string"
        },
        "UserFirstName": {
          "type""string"
        },
        "UserLastName": {
          "type""string"
        },
        "UserMobile": {
          "type""string"
        },
        "UserPhone": {
          "type""string"
        },
        "UserPsaId": {
          "type""integer"
        },
        "UserOfficeId": {
          "type""string"
        },
        "UserIsAdmin": {
          "type""boolean"
        },
        "UserIsPriority": {
          "type""boolean"
        }
      }
    },
    "Company": {
      "type""object",
      "properties": {
        "CompanyName": {
          "type""string"
        },
        "CompanyPsaId": {
          "type""integer"
        },
        "CompanyTenantId": {
          "type""string"
        }
      }
    },
    "Ticket": {
      "type""object",
      "properties": {
        "TicketId": {
          "type""integer"
        },
        "TicketSubject": {
          "type""string"
        },
        "TicketDescription": {
          "type""string"
        },
        "TicketEstimatedTime": {
          "type""integer"
        },
        "CheckList": {
          "type""string"
        },
        "Script": {
          "type""string"
        },
        "Questions": {
          "type""array",
          "items": {
            "type""object",
            "properties": {
              "Id": {
                "type""string"
              },
              "Label": {
                "type""string"
              },
              "Value": {
                "type""string"
              }
            },
            "required": [
              "Id",
              "Label",
              "Value"
            ]
          }
        }
      }
    },
    "Feedback": {
      "type""object",
      "properties": {
        "FeedbackRating": {
          "type""integer"
        },
        "FeedbackSentiment": {
          "type""integer"
        },
        "FeedbackComment": {
          "type""string"
        },
        "FeedbackPhone": {
          "type""string"
        }
      }
    },
    "Routing": {
      "type""object",
      "properties": {
        "RoutingBoard": {
          "type""string"
        },
        "RoutingStatus": {
          "type""string"
        },
        "RoutingType": {
          "type""string"
        },
        "RoutingSubType": {
          "type""string"
        },
        "RoutingItem": {
          "type""string"
        },
        "RoutingPriority": {
          "type""string"
        },
        "RoutingSource": {
          "type""string"
        },
        "RoutingIsNeedsApproval": {
          "type""boolean"
        }
      }
    },
    "Agent": {
      "type""object",
      "properties": {
        "AgentId": {
          "type""integer"
        },
        "AgentFirstName": {
          "type""string"
        },
        "AgentLastName": {
          "type""string"
        },
        "AgentEmail": {
          "type""string"
        }
      }
    }
  }
}
 
 
 
Thanks,
David
ekarim2020
Super User
Super User

Here is one possible solution for you. It works by taking the original JSON array data, transforming it into a simplified JSON object from which we can easily refer to each JSON property (First name, Last name, Job Title etc):

ekarim2020_5-1627987516734.png

This is the summary of the entire flow which you can create and follow along to determine if this will suit your needs:

ekarim2020_6-1627987718398.png

Starting with the raw JSON data:

ekarim2020_0-1627983895644.png

You can copy and paste the JSON below:

 

[
  {
    "Id": "first101",
    "Label": "First",
    "Value": "Bob"
  },
  {
    "Id": "last102",
    "Label": "Last",
    "Value": "Smith"
  },
  {
    "Id": "title103",
    "Label": "Job Title",
    "Value": "IT Manager"
  },
  {
    "Id": "mobile104",
    "Label": "Mobile Phone",
    "Value": "0123456789"
  }
]

 

Initialise three variables:

ekarim2020_2-1627984190326.png

Use Apply to each to iterate through all the JSON array. We build the a new JSON object, one property at a time in varQuestion. We add a new property to  varQuestion using the addProperty function starting with the first element in the (Compose My JSON) JSON array with ID="first101", then the next element with ID=last102, then title103 and finally mobile104:

ekarim2020_3-1627986206191.png

You can copy and past the following values for the above:

 

@{items('Apply_to_each')['Label']}
@{items('Apply_to_each')['Value']}
@{addProperty(variables('varQuestions'),variables('varLabel'), variables('varValue'))}
@{outputs('String_Property')}

 

We now have a new JSON object in varQuestions and it looks like this:

ekarim2020_0-1627988880785.png

We next add a Compose action using varQuestions as the input so that we can easily reference each property value:

ekarim2020_4-1627986632447.png

The input values for compose can be copied from here:

 

@{variables('varQuestions')}
@{outputs('Compose')['First']}
@{outputs('Compose')['Last']}
@{outputs('Compose')['Job Title']}
@{outputs('Compose')['Mobile Phone']}

 

We reference the properties using the following format:

ekarim2020_1-1627989059184.png

ekarim2020_0-1627990835025.png

And finally, you can add these values to a SharePoint list.

 

Hope this helps.

Ellis

Hi @ekarim2020 ,

 

Thank you so much this has worked perfectly, exactly what i needed. Appreciate your help and the very helpful (and detailed) steps

Awesome instructions here, used this to solve my issues as well (https://powerusers.microsoft.com/t5/General-Power-Automate/Export-REST-API-Output-To-An-Excel-Table/...)

 

Thanks

Dinerz
Helper II
Helper II

Hi All,

 

I'm using the above solution for my data query and it works perfect but If I try using this solution in an Apply to Each loop I get the error below in my "Compose Data" using "@{addProperty(variables('varQuestions'),variables('varname'), variables('varvalue'))}"

 

Error:

InvalidTemplate. Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language function 'addProperty' expects the property to not exist in the object. Unable to add property 'OUT_Assigned Group' to '{ "OUT_Assigned Group": "", "OUT_Resolution": "" }' as it already exists.'.

 

Anyone have any ideas?

 

Helpful resources

Announcements

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (4,886)