Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Unanswered

Looking for xpath expression to get specific data from JSON object

(0) ShareShare
ReportReport
Posted on by 75

Hi Community!

 

I have a JSON payload that I want to get a specific piece of data from.

 

Here is the payload (with private information removed):

 

 

{
 "id": "114106571079",
 "recipient_id": "",
 "collection_mode": "default",
 "response_status": "completed",
 "custom_value": "",
 "first_name": "",
 "last_name": "",
 "email_address": "",
 "ip_address": "",
 "logic_path": {},
 "metadata": {
 "respondent": {
 "user_agent": {
 "type": "number",
 "value": 000
 },
 "language": {
 "type": "string",
 "value": "en"
 }
 },
 "contact": {}
 },
 "page_path": [],
 "collector_id": "422326501",
 "survey_id": "402862451",
 "custom_variables": {},
 "edit_url": "",
 "analyze_url": "",
 "total_time": 13,
 "date_modified": "2022-08-31T01:44:54+00:00",
 "date_created": "2022-08-31T01:44:41+00:00",
 "href": "",
 "questions": [
 {
 "id": "87023139",
 "answers": [
 {
 "choice_id": "682016455",
 "simple_text": "Integrated Assurance"
 }
 ],
 "family": "single_choice",
 "subtype": "menu",
 "heading": ""
 },
 {
 "id": "87019079",
 "answers": [
 {
 "choice_id": "682001918",
 "row_id": "681994084",
 "choice_metadata": {
 "weight": "-10"
 },
 "simple_text": ""
 },
 {
 "choice_id": "682001919",
 "row_id": "681994085",
 "choice_metadata": {
 "weight": "-5"
 },
 "simple_text": ""
 },
 {
 "choice_id": "682001921",
 "row_id": "681994086",
 "choice_metadata": {
 "weight": "5"
 },
 "simple_text": ""
 },
 {
 "choice_id": "682001920",
 "row_id": "681994087",
 "choice_metadata": {
 "weight": "0"
 },
 "simple_text": ""
 }
 ],
 "family": "matrix",
 "subtype": "rating",
 "heading": ""
 }
 ]
}

 

 

 

I am trying to get to the "answers/choice_id" of "questions/id"=87023139

 

How would I format this in xpath?

 

 

Thanks in advance!

 

 

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at
    Re: Looking for xpath expression to get specific data from JSON object

    Hi @Brendan1 

     

    This would allow you to query the JSON as XML:

     

    DamoBird365_0-1662061772321.png

     

    And using XPath online real-time tester, evaluator and generator for XML & HTML (xpather.com) I can search as follows:

     

    DamoBird365_1-1662062223098.png

     

    with query //questions[id=87019079]/answers/choice_id but I get nothing returned if I run that query in Power Automate as xpath(outputs('ComposeXML'),'//questions[id=87019079]/answers/choice_id').

     

    Based on your required output, presumably a CSV?  You could create that by extending the filter I created previously to give the following output:

    DamoBird365_2-1662062883261.png

     

    Here is the flow:

     

    DamoBird365_3-1662063096807.png

     

    Please let me know if that is what you are looking for and/or if you solve the Xpath route you were thinking of following.


    Cheers
    Damien

    Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts. Thanks

     

     

     

  • erofee Profile Picture
    75 on at
    Re: Looking for xpath expression to get specific data from JSON object

    Thanks @DamoBird365 ,

     

    The reason I was approaching with xpath is because I need to select siblings of a specific row_id.  I reasoned if someone could show me the basic xpath syntax I could work out the rest.  Conversion to XML I didn't think would be a problem as xml() can convert valid JSON to XML: Converting JSON to XML and XML to JSON in a Flow | Power Automate | D365 Demystified

     

    I am ultimately trying to get all of the data I need into a single line for insertion into an excel table.

     

    I.e. trying to get a line that looks like this:

    email_address  ip_address  row_id_681994084_choice_id  row_id_681994084_simple_text  row_id_681994086_choice_id  row_id_681994086_simple_text  etc....
    datadatadatadatadatadata 

     

    The "row ids" will always be the same, so I don't need to select them via index or anything fancy like that.  I just need to get the siblings of a specific row_id.

     

    Do you have a different way you would approach this?

     

     

     

    Thanks,

    Brendan

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at
    Re: Looking for xpath expression to get specific data from JSON object

    Hi @Brendan1 

     

    Is there any specific reason you want to use xpath?  You would have to convert the JSON [{}] into XML <tag></tag> and then feed it into XPATH but you can achieve what you are looking for with Filter and then selecting the first result as follows:

     

    DamoBird365_5-1661932807360.png


    Cheers
    Damien

    Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts. Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >