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"
}
}
}
}
}
@body('Parse_JSON')['employees'] is the input to foreach and it will work
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.
@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']
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']
Michael E. Gernaey
497
Super User 2025 Season 1
David_MA
436
Super User 2025 Season 1
Riyaz_riz11
244
Super User 2025 Season 1