Hello,
I am trying to create a schema for JSON data I am receiving from a HTTP get operation. Sample JSON and schema (created by flow) is below. Trouble seems to be with the notes field which is returned differently depending on if its empty or contains notes.
How do I fix the schema to account for this? (I can't change the JSON as its from an external API)
Thanks in advance!
Error
[
{
"message": "Invalid type. Expected Object but got Array.",
"lineNumber": 0,
"linePosition": 0,
"path": "[1].notes",
"schemaId": "#/items/properties/notes",
"errorType": "type",
"childErrors": []
},
{
"message": "Invalid type. Expected Object but got Array.",
"lineNumber": 0,
"linePosition": 0,
"path": "[2].notes",
"schemaId": "#/items/properties/notes",
"errorType": "type",
"childErrors": []
},
{
"message": "Invalid type. Expected Object but got Array.",
"lineNumber": 0,
"linePosition": 0,
"path": "[3].notes",
"schemaId": "#/items/properties/notes",
"errorType": "type",
"childErrors": []
},
{
"message": "Invalid type. Expected Object but got Array.",
"lineNumber": 0,
"linePosition": 0,
"path": "[9].notes",
"schemaId": "#/items/properties/notes",
"errorType": "type",
"childErrors": []
}
]
Example Schema
{
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"employeeId": {
"type": "string"
},
"status": {
"type": "object",
"properties": {
"lastChanged": {
"type": "string"
},
"lastChangedByUserId": {
"type": "string"
},
"status": {
"type": "string"
}
}
},
"name": {
"type": "string"
},
"start": {
"type": "string"
},
"end": {
"type": "string"
},
"created": {
"type": "string"
},
"type": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"icon": {
"type": "string"
}
}
},
"amount": {
"type": "object",
"properties": {
"unit": {
"type": "string"
},
"amount": {
"type": "string"
}
}
},
"actions": {
"type": "object",
"properties": {
"view": {
"type": "boolean"
},
"edit": {
"type": "boolean"
},
"cancel": {
"type": "boolean"
},
"approve": {
"type": "boolean"
},
"deny": {
"type": "boolean"
},
"bypass": {
"type": "boolean"
}
}
},
"dates": {
"type": "object",
"properties": {
"2020-05-01": {
"type": "string"
},
"2020-05-02": {
"type": "string"
},
"2020-05-03": {
"type": "string"
},
"2020-05-04": {
"type": "string"
},
"2020-05-05": {
"type": "string"
}
}
},
"notes": {
"type": "object",
"properties": {
"employee": {
"type": "string"
}
}
}
},
"required": [
"id",
"employeeId",
"status",
"name",
"start",
"end",
"created",
"type",
"amount",
"actions",
"dates",
"notes"
]
}
}
Example JSON
[
{
"id": "4602",
"employeeId": "204",
"status": {
"lastChanged": "2020-02-27",
"lastChangedByUserId": "2677",
"status": "canceled"
},
"name": "Homer Simpson",
"start": "2020-05-01",
"end": "2020-05-05",
"created": "2020-02-04",
"type": {
"id": "82",
"name": "Vacation",
"icon": "palm-trees"
},
"amount": {
"unit": "days",
"amount": "3"
},
"actions": {
"view": true,
"edit": false,
"cancel": false,
"approve": false,
"deny": false,
"bypass": false
},
"dates": {
"2020-05-01": "1",
"2020-05-02": "0",
"2020-05-03": "0",
"2020-05-04": "1",
"2020-05-05": "1"
},
"notes": {
"employee": "vacation "
}
},
{
"id": "4974",
"employeeId": "99",
"status": {
"lastChanged": "2020-04-28",
"lastChangedByUserId": "2686",
"status": "approved"
},
"name": "Bart Simpson",
"start": "2020-05-05",
"end": "2020-05-05",
"created": "2020-04-03",
"type": {
"id": "82",
"name": "Vacation",
"icon": "palm-trees"
},
"amount": {
"unit": "days",
"amount": "1"
},
"actions": {
"view": true,
"edit": false,
"cancel": false,
"approve": false,
"deny": false,
"bypass": false
},
"dates": {
"2020-05-05": "1"
},
"notes": []
}
]
Hi @PancakeMaker99,
If the notes are not sure whether it has value, you could create multiple types of the note:
"notes": {
"type": ["object","array"],
"properties": {
"employee": {
"type": "string"
}
}
}
So, the whole JSON schema could be:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"employeeId": {
"type": "string"
},
"status": {
"type": "object",
"properties": {
"lastChanged": {
"type": "string"
},
"lastChangedByUserId": {
"type": "string"
},
"status": {
"type": "string"
}
}
},
"name": {
"type": "string"
},
"start": {
"type": "string"
},
"end": {
"type": "string"
},
"created": {
"type": "string"
},
"type": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"icon": {
"type": "string"
}
}
},
"amount": {
"type": "object",
"properties": {
"unit": {
"type": "string"
},
"amount": {
"type": "string"
}
}
},
"actions": {
"type": "object",
"properties": {
"view": {
"type": "boolean"
},
"edit": {
"type": "boolean"
},
"cancel": {
"type": "boolean"
},
"approve": {
"type": "boolean"
},
"deny": {
"type": "boolean"
},
"bypass": {
"type": "boolean"
}
}
},
"dates": {
"type": "object",
"properties": {
"2020-05-01": {
"type": "string"
},
"2020-05-02": {
"type": "string"
},
"2020-05-03": {
"type": "string"
},
"2020-05-04": {
"type": "string"
},
"2020-05-05": {
"type": "string"
}
}
},
"notes": {
"type": ["object","array"],
"properties": {
"employee": {
"type": "string"
}
}
}
},
"required": [
"id",
"employeeId",
"status",
"name",
"start",
"end",
"created",
"type",
"amount",
"actions",
"dates",
"notes"
]
}
}
Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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