Handle Nulls In Parse JSON Action In Power Automate

Introduction

Whenever you're working with JSON payloads in power automate, there's always a possibility of receiving null values inside JSON, where Parse JSON Action will be errored out because of these null values. To handle this we have to modify the schema of the generated schema for the provided JSON.

Step 1

Login to the required Power Apps environment using URL make.powerapps.com by providing username and password and click on Flows on the left-hand side as shown in the below figure.

Handle Nulls in Parse JSON Action in Power Automate

Step 2

After Step 1, Click on New Flow and select instant cloud flow and provide the trigger as Manually trigger a flow and click on Create as shown in the below figure.

Handle Nulls in Parse JSON Action in Power Automate

Step 3

After Step 2, name the flow as Handle Null Values in Json and under Manually trigger a flow select an initialize variable action and provide the values as

Name: CustomerJson
Type: Array
Value: [{
    "Name": "Venkat",
    "EmpId": 1234,
    "Mobile": 9834523456
}, {
    "Name": null,
    "EmpId": 4567
}]

as shown in the below figure.

Handle Nulls in Parse JSON Action in Power Automate

Step 4

After Step 3, Take Parse JSON action and under schema generate from sample copy and paste the JSON which we provided in Step 3 and provide the inputs as below

Content: {
    variables('CustomerJson')
}
Schema: {
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "Name": {
                "type": "string"
            },
            "EmpId": {
                "type": "integer"
            },
            "Mobile": {
                "type": "integer"
            }
        },
        "required": ["Name", "EmpId"]
    }
}

as shown in the below figure.

Handle Nulls in Parse JSON Action in Power Automate Figure 4

Step 5

After Step 4, save and test the flow and you should see an error

as shown in the below figure.

Handle Nulls in Parse JSON Action in Power Automate

Step 6

After Step 5, to resolve this error go back to Step 4 and modify schema for Name property from string to empty value {} like below

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "Name": {},
            "EmpId": {
                "type": "integer"
            },
            "Mobile": {
                "type": "integer"
            }
        },
        "required": ["Name", "EmpId"]
    }
}

as shown in the below figure.

Handle Nulls in Parse JSON Action in Power Automate Figure 6

Step 7

After Step 6, take apply each loop action and provide the following inputs as

Select an output from previous steps : @{body('Parse_JSON')}

And take Compose action and provide the inputs as

Inputs : @{items('Apply_to_each')['Name']}

as shown in the below figure.

Handle Nulls in Parse JSON Action in Power Automate

Step 8

After Step 7, now save and test the flow and you can see the flow runs without an issue and you can see null values as shown in the below figure

Handle Nulls in Parse JSON Action in Power Automate

Note

  1. For all null values make sure to handle them in the above mentioned way otherwise Parse JSON action will fail.

Conclusion

In this way, we can easily handle null values in Parse Json Action.


Similar Articles