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']

 

 

 

View solution in original post

3 REPLIES 3
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']

 

 

 

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.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (4,476)