cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Process JSON Response to See if Property Matches a Condition

I am new to Power Automate and I am trying to build a flow that processes a JSON response and saves a property in the response if there is a particular value in a field.  I can't figure out how to loop through to test the property I want to.

I am trying to loop through the response file and evaluate if Related 1 = Value3, then store Value4 from Related 2 into the variable.

I have tried

  • Initialize Variable
  • Parse JSON
  • Apply to Each
    • condition 
    • Set Variable

My issues appears to be in the apply for each step.  I keep getting an error related to a value being Null when it needs to be Array.  

Thank you for any assistance.

 

Sample JSON Response

 

{
  "id": 123456,
  "fields": {
    "Field1": "Value1",
    "Field2": "Value2",
  },
  "Related": [
    {
      "Related1": "Value3",
      "Related2": "Value4,
    },
    {
      "Related1": "Value5",
      "Related2": "Value6",
    }
  ]
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Process JSON Response to See if Property Matches a Condition

Hi @MAT1982 ,

 

The provided JSON isn't correct, the correct JSON should as below:

{
  "id": 123456,
  "fields": {
    "Field1": "Value1",
    "Field2": "Value2"
  },
  "Related": [
    {
      "Related1": "Value3",
      "Related2": "Value4"
    },
    {
      "Related1": "Value5",
      "Related2": "Value6"
    }
  ]
}

 

And you could use the correct JSON to create the flow as below:

1.png2.png

 

The schema for the JSON as below:

{
    "type": "object",
    "properties": {
        "id": {
            "type": "integer"
        },
        "fields": {
            "type": "object",
            "properties": {
                "Field1": {
                    "type": "string"
                },
                "Field2": {
                    "type": "string"
                }
            }
        },
        "Related": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "Related1": {
                        "type": "string"
                    },
                    "Related2": {
                        "type": "string"
                    }
                },
                "required": [
                    "Related1",
                    "Related2"
                ]
            }
        }
    }
}

 

Best Regards,

Alice

 

Community Support Team _ Alice Zhang
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
Highlighted
Resolver II
Resolver II

Re: Process JSON Response to See if Property Matches a Condition

@MAT1982 

 

Is following what you want ?

 

getAttributeFromArray.png

 

Highlighted
Community Support
Community Support

Re: Process JSON Response to See if Property Matches a Condition

Hi @MAT1982 ,

 

The provided JSON isn't correct, the correct JSON should as below:

{
  "id": 123456,
  "fields": {
    "Field1": "Value1",
    "Field2": "Value2"
  },
  "Related": [
    {
      "Related1": "Value3",
      "Related2": "Value4"
    },
    {
      "Related1": "Value5",
      "Related2": "Value6"
    }
  ]
}

 

And you could use the correct JSON to create the flow as below:

1.png2.png

 

The schema for the JSON as below:

{
    "type": "object",
    "properties": {
        "id": {
            "type": "integer"
        },
        "fields": {
            "type": "object",
            "properties": {
                "Field1": {
                    "type": "string"
                },
                "Field2": {
                    "type": "string"
                }
            }
        },
        "Related": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "Related1": {
                        "type": "string"
                    },
                    "Related2": {
                        "type": "string"
                    }
                },
                "required": [
                    "Related1",
                    "Related2"
                ]
            }
        }
    }
}

 

Best Regards,

Alice

 

Community Support Team _ Alice Zhang
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

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

Top Solution Authors
Top Kudoed Authors
Users online (9,138)