cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
therush321
Helper II
Helper II

Cannot Parse JSON - The result must be a valid array.

Hi All

 

I am having issues trying to parse a JSON then store the data in a sql table. Would really appreciate some help on this one.

Error below:
The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@body('Parse_JSON')?['body']?['employees']' is of type 'Null'. The result must be a valid array.

My JSON Schema:

 

{
    "type": "object",
    "properties": {
        "body": {
            "type": "object",
            "properties": {
                "title": {
                    "type": "string"
                },
                "fields": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "type": {
                                "type": "string"
                            },
                            "name": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "id",
                            "type",
                            "name"
                        ]
                    }
                },
                "employees": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "91": {
                                "type": "string"
                            },
                            "id": {
                                "type": "string"
                            },
                            "employeeNumber": {
                                "type": "string"
                            },
                            "firstName": {
                                "type": "string"
                            },
                            "lastName": {
                                "type": "string"
                            },
                            "jobTitle": {
                                "type": "string"
                            },
                            "customCultureManager2": {},
                            "customTeamName": {},
                            "photoUploaded": {
                                "type": "boolean"
                            },
                            "photoUrl": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "91",
                            "id",
                            "employeeNumber",
                            "firstName",
                            "lastName",
                            "jobTitle",
                            "customCultureManager2",
                            "customTeamName",
                            "photoUploaded",
                            "photoUrl"
                        ]
                    }
                }
            }
        },
        "statusCode": {
            "type": "integer"
        },
        "headers": {
            "type": "object",
            "properties": {
                "Transfer-Encoding": {
                    "type": "string"
                },
                "Connection": {
                    "type": "string"
                },
                "Pragma": {
                    "type": "string"
                },
                "Strict-Transport-Security": {
                    "type": "string"
                },
                "Vary": {
                    "type": "string"
                },
                "X-Content-Type-Options": {
                    "type": "string"
                },
                "Cache-Control": {
                    "type": "string"
                },
                "Date": {
                    "type": "string"
                },
                "Server": {
                    "type": "string"
                },
                "Content-Type": {
                    "type": "string"
                },
                "Expires": {
                    "type": "string"
                },
                "Content-Length": {
                    "type": "string"
                }
            }
        }
    }
}

 

 

 



therush321_0-1636727224672.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @therush321,

 

The error suggests that the employee array is empty (because of the null value error message). Can you check if the parse json output contains any value in that field?

 

Additionally I noticed that the expression/value you are using in the apply to each input is using the body property twice. (One via the body function and the second as a property after the ?). Looking at your schema you only have one body property.

 

Can you try the expression below in the input field of your apply to each:

 

 

body('Parse_JSON')?['employees']

 

 

 

If that doesn't work you could also try and use the outputs function instead:

 

 

outputs('Parse_JSON')?['body']?['employees']

 

 

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


View solution in original post

4 REPLIES 4
Expiscornovus
Super User
Super User

Hi @therush321,

 

The error suggests that the employee array is empty (because of the null value error message). Can you check if the parse json output contains any value in that field?

 

Additionally I noticed that the expression/value you are using in the apply to each input is using the body property twice. (One via the body function and the second as a property after the ?). Looking at your schema you only have one body property.

 

Can you try the expression below in the input field of your apply to each:

 

 

body('Parse_JSON')?['employees']

 

 

 

If that doesn't work you could also try and use the outputs function instead:

 

 

outputs('Parse_JSON')?['body']?['employees']

 

 

 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


therush321
Helper II
Helper II

@Expiscornovus  Thank you very much.

I changed the expression for the input field of the apply to each to the one you mentioned and it now works well.
 

 body('Parse_JSON')?['employees']

Any idea on what might be causing the double 'body' in parsing?  I am having the same issue with a whole other dataset.  I can get it to parse using your expression above, but it still won't let me do anything with it after that.  Keeps wanting to embed new commands in another Apply to Each command.

@body('Parse_JSON')['employees'] is the input to foreach and it will work

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.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (3,138)