cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MAT1982
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
v-alzhan-msft
Community Support
Community Support

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
MinRao
Resolver II
Resolver II

@MAT1982 

 

Is following what you want ?

 

getAttributeFromArray.png

 

v-alzhan-msft
Community Support
Community Support

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.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (3,596)