John John
John John

Reputation: 1

Parse JSON is raising this error inside some DoUntil iterations "Invalid type. Expected String but got Null."

I have the following schema inside my Parse JSON action inside Power Automate Flow:-

{
  "type": "object",
  "properties": {
    "_id": {
      "type": "object",
      "properties": {
        "$oid": {
          "type": "string"
        }
      }
    },
    "normalized_otherCategory": {
      "type": "string"
    },
    "category": {
      "type": "string"
    },
    "otherCategory": {
      "type": "string"
    },
    "location": {
      "type": "string"
    },
    "referenceNumber": {
      "type": "string"
    },
    "archivingDate": {
      "type": "object",
      "properties": {
        "$date": {
          "type": "string"
        }
      }
    },
    "actions": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "object",
            "properties": {
              "$oid": {
                "type": "string"
              }
            }
          },
          "type": {
            "type": "string"
          },
          "user": {
            "type": "string"
          },
          "timestamp": {
            "type": "object",
            "properties": {
              "$date": {
                "type": "string"
              }
            }
          },
          "normalized_comment": {
            "type": "array"
          },
          "configs": {
            "type": "array"
          },
          "comment": {
            "type": "string"
          }
        },
        "required": [
          "_id",
          "type",
          "user",
          "timestamp",
          "normalized_comment",
          "configs"
        ]
      }
    },
    "otherAttributes": {
      "type": "array"
    },
    "attributes": {
      "type": "array"
    },
    "timestamp": {
      "type": "object",
      "properties": {
        "$date": {
          "type": "string"
        }
      }
    },
    "foundDate": {
      "type": "object",
      "properties": {
        "$date": {
          "type": "string"
        }
      }
    },
    "trainFoundAt": {
      "type": "object",
      "properties": {
        "number": {
          "type": "string"
        },
        "car": {
          "type": "string"
        },
        "seat": {
          "type": "string"
        }
      }
    },
    "status": {
      "type": "string"
    },
    "matchIdNumber": {
      "type": "string"
    },
    "__v": {
      "type": "integer"
    },
    "imageData": {
      "type": "object",
      "properties": {
        "originalName": {
          "type": "string"
        },
        "contentType": {
          "type": "string"
        },
        "data": {
          "type": "object",
          "properties": {
            "$binary": {
              "type": "string"
            },
            "$type": {
              "type": "string"
            }
          }
        }
      }
    },
    "imageThumbData": {
      "type": "object",
      "properties": {
        "originalName": {
          "type": "string"
        },
        "contentType": {
          "type": "string"
        },
        "data": {
          "type": "object",
          "properties": {
            "$binary": {
              "type": "string"
            },
            "$type": {
              "type": "string"
            }
          }
        }
      }
    },
    "stationFoundAt": {
      "type": "string"
    }
  },
  "required": [
    "_id",
    "normalized_otherCategory",
    "category",
    "location",
    "referenceNumber",
    "archivingDate",
    "actions",
    "otherAttributes",
    "attributes",
    "timestamp",
    "foundDate",
    "status",
    "matchIdNumber",
    "__v"
  ]
}

but it is raising this error on 5% of the items, while working well for the other 95% items:-

{
    "errors": [
        {
            "message": "Invalid type. Expected String but got Null.",
            "lineNumber": 0,
            "linePosition": 0,
            "path": "stationFoundAt",
            "schemaId": "#/properties/stationFoundAt",
            "errorType": "type",
            "childErrors": []
        }
    ]
}

here is a sample of one of the inputs which is raising this error:-

{
    "content": {
        "_id": {
            "$oid": "5daa037cb66a2c601510e8aa"
        },
        "normalized_otherCategory": "purse,type,wallet",
        "category": "other",
        "otherCategory": "Purse-Type Wallet",
        "location": "ontrain",
        "referenceNumber": "VIAF-000009475",
        "archivingDate": {
            "$date": "2019-11-15T00:00:00.000Z"
        },
        "actions": [
            {
                "user": "PA454196",
                "type": "created",
                "_id": {
                    "$oid": "5daa037cb66a2c601510e8a9"
                },
                "timestamp": {
                    "$date": "2019-10-18T18:25:00.426Z"
                },
                "normalized_comment": [],
                "configs": []
            },
            {
                "_id": {
                    "$oid": "5daa037cb66a2c601510e8a8"
                },
                "user": "PA454196",
                "comment": "",
                "type": "comment",
                "timestamp": {
                    "$date": "2019-10-18T18:25:00.425Z"
                },
                "normalized_comment": [],
                "configs": []
            },
            {
                "_id": {
                    "$oid": "5daa037cb66a2c601510e8a7"
                },
                "user": "PA454196",
                "type": "stored",
                "timestamp": {
                    "$date": "2019-10-18T18:25:00.425Z"
                },
                "normalized_comment": [],
                "configs": [
                    "container-1",
                    "station-toronto"
                ]
            },
            {
                "_id": {
                    "$oid": "5daa03b9b66a2c601510e8ab"
                },
                "user": "PA454196",
                "type": "comment",
                "comment": "black nylon",
                "timestamp": {
                    "$date": "2019-10-18T00:00:00.000Z"
                },
                "normalized_comment": [
                    "black",
                    "nylon"
                ],
                "configs": []
            },
            {
                "_id": {
                    "$oid": "5db1d7481fccee641499efd1"
                },
                "user": "GR452944",
                "type": "comment",
                "comment": "pax lives in Australia. currently awaiting for Address and authorization to send to Australia from Management ",
                "timestamp": {
                    "$date": "2019-10-24T00:00:00.000Z"
                },
                "normalized_comment": [
                    "pax",
                    "lives",
                    "in",
                    "australia",
                    "currently",
                    "awaiting",
                    "for",
                    "address",
                    "and",
                    "authorization",
                    "to",
                    "send",
                    "to",
                    "australia",
                    "from",
                    "management"
                ],
                "configs": []
            },
            {
                "comment": "Bryan Lim\n12/3 Rockley Road\nSouth Yarra\nVictoria \nAUSTRALIA 3141\n",
                "type": "comment",
                "user": "GR452944",
                "_id": {
                    "$oid": "5db9d0d53da9956709808899"
                },
                "timestamp": {
                    "$date": "2019-10-30T00:00:00.000Z"
                },
                "normalized_comment": [
                    "bryan",
                    "lim",
                    "123",
                    "rockley",
                    "road",
                    "south",
                    "yarra",
                    "victoria",
                    "australia",
                    "3141"
                ],
                "configs": []
            },
            {
                "comment": "OCT 30- Sent by Canada Post, tracking number LX035418234CA",
                "type": "comment",
                "user": "CH454138",
                "_id": {
                    "$oid": "5db9d73d8e450c67172d0dea"
                },
                "timestamp": {
                    "$date": "2019-10-30T00:00:00.000Z"
                },
                "normalized_comment": [
                    "oct",
                    "30",
                    "sent",
                    "by",
                    "canada",
                    "post",
                    "tracking",
                    "number",
                    "lx035418234ca"
                ],
                "configs": []
            }
        ],
        "otherAttributes": [],
        "attributes": [],
        "timestamp": {
            "$date": "2019-10-18T18:25:00.423Z"
        },
        "foundDate": {
            "$date": "2019-10-16T00:00:00.000Z"
        },
        "trainFoundAt": {
            "number": "55",
            "car": "3323",
            "seat": ""
        },
        "status": "opened",
        "pnrNumber": "VWZ975",
        "matchIdNumber": "",
        "__v": 4,
        "imageData": {
            "originalName": "20191018_142530[1].jpg_big.jpg",
            "contentType": "images/jpeg",
            "data": {
                "$binary": "/9j/*****5qTxPbNfy2t/dMp3oEVd2Oe4FUb/w9O0dvd3xd4VTYis+Qgz0zWW/ZUTalof02pLM266i8pVR2G4gCuo9o9vJB4fuEjV1LhjGhPKrj3rql0Ks/9k=",
                "$type": "00"
            }
        },
        "imageThumbData": {
            "originalName": "20191018_142530[1].jpg_thumb.jpg",
            "contentType": "images/jpeg",
            "data": {
                "$binary": "/9j/***SP/2Q==",
                "$type": "00"
            }
        },
        "stationFoundAt": null
    },
    "schema": {
        "type": "object",
        "properties": {
            "_id": {
                "type": "object",
                "properties": {
                    "$oid": {
                        "type": "string"
                    }
                }
            },
            "normalized_otherCategory": {
                "type": "string"
            },
            "category": {
                "type": "string"
            },
            "otherCategory": {
                "type": "string"
            },
            "location": {
                "type": "string"
            },
            "referenceNumber": {
                "type": "string"
            },
            "archivingDate": {
                "type": "object",
                "properties": {
                    "$date": {
                        "type": "string"
                    }
                }
            },
            "actions": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "_id": {
                            "type": "object",
                            "properties": {
                                "$oid": {
                                    "type": "string"
                                }
                            }
                        },
                        "type": {
                            "type": "string"
                        },
                        "user": {
                            "type": "string"
                        },
                        "timestamp": {
                            "type": "object",
                            "properties": {
                                "$date": {
                                    "type": "string"
                                }
                            }
                        },
                        "normalized_comment": {
                            "type": "array"
                        },
                        "configs": {
                            "type": "array"
                        },
                        "comment": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "_id",
                        "type",
                        "user",
                        "timestamp",
                        "normalized_comment",
                        "configs"
                    ]
                }
            },
            "otherAttributes": {
                "type": "array"
            },
            "attributes": {
                "type": "array"
            },
            "timestamp": {
                "type": "object",
                "properties": {
                    "$date": {
                        "type": "string"
                    }
                }
            },
            "foundDate": {
                "type": "object",
                "properties": {
                    "$date": {
                        "type": "string"
                    }
                }
            },
            "trainFoundAt": {
                "type": "object",
                "properties": {
                    "number": {
                        "type": "string"
                    },
                    "car": {
                        "type": "string"
                    },
                    "seat": {
                        "type": "string"
                    }
                }
            },
            "status": {
                "type": "string"
            },
            "matchIdNumber": {
                "type": "string"
            },
            "__v": {
                "type": "integer"
            },
            "imageData": {
                "type": "object",
                "properties": {
                    "originalName": {
                        "type": "string"
                    },
                    "contentType": {
                        "type": "string"
                    },
                    "data": {
                        "type": "object",
                        "properties": {
                            "$binary": {
                                "type": "string"
                            },
                            "$type": {
                                "type": "string"
                            }
                        }
                    }
                }
            },
            "imageThumbData": {
                "type": "object",
                "properties": {
                    "originalName": {
                        "type": "string"
                    },
                    "contentType": {
                        "type": "string"
                    },
                    "data": {
                        "type": "object",
                        "properties": {
                            "$binary": {
                                "type": "string"
                            },
                            "$type": {
                                "type": "string"
                            }
                        }
                    }
                }
            },
            "stationFoundAt": {
                "type": "string"
            }
        },
        "required": [
            "_id",
            "normalized_otherCategory",
            "category",
            "location",
            "referenceNumber",
            "archivingDate",
            "actions",
            "otherAttributes",
            "attributes",
            "timestamp",
            "foundDate",
            "status",
            "matchIdNumber",
            "__v"
        ]
    }
}

here is a JSON which was parsed successfully:-

{
    "content": {
        "_id": {
            "$oid": "5dde57bffeaf3f770907b144"
        },
        "normalized_otherCategory": "books,of,numbers",
        "category": "books",
        "otherCategory": "books of numbers",
        "location": "ontrain",
        "referenceNumber": "VIAF-000010334",
        "archivingDate": {
            "$date": "2020-02-24T00:00:00.000Z"
        },
        "actions": [
            {
                "_id": {
                    "$oid": "5dde57bffeaf3f770907b143"
                },
                "type": "created",
                "user": "SO202505",
                "timestamp": {
                    "$date": "2019-11-27T11:02:23.899Z"
                },
                "normalized_comment": [],
                "configs": []
            },
            {
                "type": "comment",
                "comment": "",
                "user": "SO202505",
                "_id": {
                    "$oid": "5dde57bffeaf3f770907b142"
                },
                "timestamp": {
                    "$date": "2019-11-27T11:02:23.899Z"
                },
                "normalized_comment": [],
                "configs": []
            },
            {
                "type": "stored",
                "user": "SO202505",
                "_id": {
                    "$oid": "5dde57bffeaf3f770907b141"
                },
                "timestamp": {
                    "$date": "2019-11-27T11:02:23.899Z"
                },
                "normalized_comment": [],
                "configs": [
                    "container-2",
                    "station-quebec"
                ]
            }
        ],
        "otherAttributes": [],
        "attributes": [],
        "timestamp": {
            "$date": "2019-11-27T11:02:23.898Z"
        },
        "foundDate": {
            "$date": "2019-11-26T00:00:00.000Z"
        },
        "trainFoundAt": {
            "number": "28",
            "car": "3",
            "seat": "12c"
        },
        "status": "opened",
        "pnrNumber": "",
        "matchIdNumber": "",
        "__v": 0,
        "imageData": {
            "originalName": "WIN_20191127_05_55_39_Pro.jpg_big.jpg",
            "contentType": "images/jpeg",
            "data": {
                "$binary": "/9j/2****oI2SuUUUI/sRZ//9k=",
                "$type": "00"
            }
        },
        "imageThumbData": {
            "originalName": "WIN_20191127_05_55_39_Pro.jpg_thumb.jpg",
            "contentType": "images/jpeg",
            "data": {
                "$binary": "/9j/****Bn//2Q==",
                "$type": "00"
            }
        }
    },
    "schema": {
        "type": "object",
        "properties": {
            "_id": {
                "type": "object",
                "properties": {
                    "$oid": {
                        "type": "string"
                    }
                }
            },
            "normalized_otherCategory": {
                "type": "string"
            },
            "category": {
                "type": "string"
            },
            "otherCategory": {
                "type": "string"
            },
            "location": {
                "type": "string"
            },
            "referenceNumber": {
                "type": "string"
            },
            "archivingDate": {
                "type": "object",
                "properties": {
                    "$date": {
                        "type": "string"
                    }
                }
            },
            "actions": {
                "type": "array",
                "items": {
                    "type": "object",
                    "properties": {
                        "_id": {
                            "type": "object",
                            "properties": {
                                "$oid": {
                                    "type": "string"
                                }
                            }
                        },
                        "type": {
                            "type": "string"
                        },
                        "user": {
                            "type": "string"
                        },
                        "timestamp": {
                            "type": "object",
                            "properties": {
                                "$date": {
                                    "type": "string"
                                }
                            }
                        },
                        "normalized_comment": {
                            "type": "array"
                        },
                        "configs": {
                            "type": "array"
                        },
                        "comment": {
                            "type": "string"
                        }
                    },
                    "required": [
                        "_id",
                        "type",
                        "user",
                        "timestamp",
                        "normalized_comment",
                        "configs"
                    ]
                }
            },
            "otherAttributes": {
                "type": "array"
            },
            "attributes": {
                "type": "array"
            },
            "timestamp": {
                "type": "object",
                "properties": {
                    "$date": {
                        "type": "string"
                    }
                }
            },
            "foundDate": {
                "type": "object",
                "properties": {
                    "$date": {
                        "type": "string"
                    }
                }
            },
            "trainFoundAt": {
                "type": "object",
                "properties": {
                    "number": {
                        "type": "string"
                    },
                    "car": {
                        "type": "string"
                    },
                    "seat": {
                        "type": "string"
                    }
                }
            },
            "status": {
                "type": "string"
            },
            "matchIdNumber": {
                "type": "string"
            },
            "__v": {
                "type": "integer"
            },
            "imageData": {
                "type": "object",
                "properties": {
                    "originalName": {
                        "type": "string"
                    },
                    "contentType": {
                        "type": "string"
                    },
                    "data": {
                        "type": "object",
                        "properties": {
                            "$binary": {
                                "type": "string"
                            },
                            "$type": {
                                "type": "string"
                            }
                        }
                    }
                }
            },
            "imageThumbData": {
                "type": "object",
                "properties": {
                    "originalName": {
                        "type": "string"
                    },
                    "contentType": {
                        "type": "string"
                    },
                    "data": {
                        "type": "object",
                        "properties": {
                            "$binary": {
                                "type": "string"
                            },
                            "$type": {
                                "type": "string"
                            }
                        }
                    }
                }
            },
            "stationFoundAt": {
                "type": "string"
            }
        },
        "required": [
            "_id",
            "normalized_otherCategory",
            "category",
            "location",
            "referenceNumber",
            "archivingDate",
            "actions",
            "otherAttributes",
            "attributes",
            "timestamp",
            "foundDate",
            "status",
            "matchIdNumber",
            "__v"
        ]
    }
}

can anyone advice how i can fix this error for the 5% of the items?

Thanks

Upvotes: 0

Views: 3545

Answers (1)

Henk van Boeijen
Henk van Boeijen

Reputation: 7948

For string properties that can be null the type declaration should be defined as { "type": ["string", "null"] }.

Upvotes: 1

Related Questions