cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AUaero
Advocate I
Advocate I

"IF" expression using output from Parse JSON

I'm retrieving a JSON payload from a web API. The payload is as follows:

{
    "@type": "QueryResult",
    "result": [
        {
            "@type": "Atom",
            "capabilities": [],
            "id": "123456",
            "name": "BoomiPD",
            "status": "ONLINE",
            "type": "MOLECULE",
            "hostName": "boomipd.foo.com",
            "dateInstalled": "2020-10-29T17:39:51Z",
            "currentVersion": "21.07.4",
            "purgeHistoryDays": 30,
            "purgeImmediate": false,
            "forceRestartTime": 10800000
        },
        {
            "@type": "Atom",
            "capabilities": [],
            "id": "7891011",
            "name": "BoomiDV",
            "status": "ONLINE",
            "type": "MOLECULE",
            "hostName": "boomidv.foo.com",
            "dateInstalled": "2020-10-30T15:47:29Z",
            "currentVersion": "21.07.4",
            "purgeHistoryDays": 7,
            "purgeImmediate": false,
            "forceRestartTime": 10800000
        }
    ],
    "numberOfResults": 2
}

I'm using the Parse JSON function to parse this out and then I'm writing the data to a streaming dataset in Power BI.  So far, so good.

AUaero_0-1631131828246.png

 

Here's where I'm struggling.  I need to populate an additional field in my streaming dataset named StatusID.  If the status of item in the array is "ONLINE" then statusID should be 1.  Otherwise statusID is 0.

 

I thought I could use an "IF" expression with dynamic content to grab "status" from the parsed record.  However, when I try this, I don't see "status" from the parsed results, I only see the top levels from the JSON array.

AUaero_1-1631131914180.png

I tried manually coding it in as 

 

if(equals(@items('For_each_record')?['status'], 'ONLINE'),1,0)

 

but Flow says that is an invalid expression.

 

Any ideass?

1 ACCEPTED SOLUTION

Accepted Solutions
DamoBird365
Microsoft
Microsoft

Hi @AUaero 

 

Just try item()?[‘status’] and don’t keep the @.

 

Damien

View solution in original post

3 REPLIES 3
DamoBird365
Microsoft
Microsoft

Hi @AUaero 

 

Just try item()?[‘status’] and don’t keep the @.

 

Damien

AUaero
Advocate I
Advocate I

@DamoBird365 thanks for your help!  I swear this syntax kills me.  🙂

DamoBird365
Microsoft
Microsoft

Haha. A bit of practice and you’ll master it. I’ve a couple videos on my YT about arrays that might be worth a watch.

 

Did you know a ? gives you null if the key doesn’t exist. If you skip the ? In the expression and the key doesn’t exist, you get an error and the flow fails. 

You could teach me a thing or two about BI I bet though.

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 (3,234)