web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Automate
Unanswered

Parse JSON Schema

(0) ShareShare
ReportReport
Posted on by 7

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": []
 }
]

 

 

Categories:
I have the same question (0)
  • Verified answer
    v-litu-msft Profile Picture
    on at

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 523 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 406 Moderator

#3
abm abm Profile Picture

abm abm 245 Most Valuable Professional

Last 30 days Overall leaderboard