Power Automate Fundamentals # 68: Handle Nulls in Parse JSON Action in Power Automate

Introduction:

Whenever working with json payload’s in power automate, 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 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.

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.

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.

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.

Step 5:

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

  as shown in the below figure.

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.

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.

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

Note:

  1. For all null values make sure to handle 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s