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

How to express a JSON path in a Compose to select a value based on a condition

Dear Power Automaters,

 

I would be grateful if you could share your thoughts on how you would select a value (e.g. Compose) based on a attribute value. For example, I would like to obtain the value of rawdata if the @attributecolumnid = 99999. The value should be 'Answer'. As you can see the structure below is also inconsistent, so each JSON path could be different based on the attributecolumnid

 

I have a Apply to Each with a condition but this is highly inefficient.

 

Many thanks

 

 

 

{
  {
    "@sequence": "12",
    "@attributecolumnid": "99999",
    "rawdata": 'Answer',
    "displaydata": 'Answer'
  },
  {
    "@sequence": "13",
    "@attributecolumnid": "90927",
    "rawdata": null,
    "displaydata": null
  },
  {
    "@sequence": "14",
    "@attributecolumnid": "89303",
    "rawdata": {
      "choices": {
        "choice": {
          "@style": "#000000",
          "label": "XXXXXXXXXX"
        }
      }
    },
    "displaydata": {
      "choices": {
        "choice": {
          "@style": "#000000",
          "label": "YYYYYYYY"
        }
      }
    }
  }
 }

 

 

 

3 REPLIES 3
manuelstgomes
Super User II
Super User II

HI @dang10041 

 

You can use "Parse JSON" and provide your JSON to generate the structure using "Generate from a sample."

 

After that, you can access each key and get the values. 

 

One issue, though. I tried to import your JSON and get errors. 

1. null is not representable in JSON

2. If you're defining the main element as a dictionary, then you need to provide a "key:value" pair. I think you want the overall to be an array so you need to replace with []

 

If you copy the code to https://jsonlint.com/ you'll see the issues.

 

Hope this helps

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

Thank you - I appreciate your suggestions @manuelstgomes however, I should mention that the JSON response is not something I have control over. Having tried Parse JSON in the past, I am being force to reference the values using JSON path. I was hoping if someone could suggest a way of doing just that.

Hi @dang10041 

 

That's a bummer. You can try to parse the text, but it's cumbersome.

 

I don't know a way to do it without using formulas to replace the first and last character with [ ] and find null and add something like "null."

 

I think those are your only two issues and then you can use "Parse JSON".

 

I hope this helps.

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Cheers
Manuel

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,103)