具有动态键的对象无法在电源自动化中生成解析 JSON 模式

问题描述 投票:0回答:1

我正在 Power Automate 中进行一个 API 调用,我收到以下 JSON 的响应

{
"paging": {
    "start": 0,
    "count": 10,
    "links": [],
    "total": 3
},
"elements": [
    {
        "isReshareDisabledByAuthor": false,
        "createdAt": 1704446818959,
        "lifecycleState": "PUBLISHED",
        "lastModifiedAt": 1704446818959,
        "visibility": "PUBLIC",
        "publishedAt": 1704446818959,
        "author": "urn:li:organization:101414444",
        "id": "urn:li:share:7148968102884841984",
        "distribution": {
            "feedDistribution": "MAIN_FEED",
            "thirdPartyDistributionChannels": []
        },
        "content": {
            "media": {
                "altText": "",
                "id": "urn:li:image:D4D22AQHbdiWdPzeHtg"
            }
        },
        "commentary": "Hi Test",
        "lifecycleStateInfo": {
            "isEditedByAuthor": false
        }
    },
    {
        "isReshareDisabledByAuthor": false,
        "createdAt": 1704285674051,
        "lifecycleState": "PUBLISHED",
        "lastModifiedAt": 1704285674096,
        "visibility": "PUBLIC",
        "publishedAt": 1704285674051,
        "author": "urn:li:organization:101414444",
        "id": "urn:li:ugcPost:7148292213186180096",
        "distribution": {
            "feedDistribution": "MAIN_FEED",
            "thirdPartyDistributionChannels": []
        },
        "content": {
            "multiImage": {
                "images": [
                    {
                        "altText": "",
                        "id": "urn:li:image:D4D22AQFnjGKot4DBIg"
                    },
                    {
                        "altText": "",
                        "id": "urn:li:image:D4D22AQEzSmXKu93lmw"
                    },
                    {
                        "altText": "",
                        "id": "urn:li:image:D4D22AQGMb7DQf3s7zA"
                    }
                ]
            }
        },
        "commentary": "Hi There",
        "lifecycleStateInfo": {
            "isEditedByAuthor": false
        }
    },
    {
        "isReshareDisabledByAuthor": false,
        "lifecycleState": "PUBLISHED",
        "createdAt": 1703744862033,
        "lastModifiedAt": 1703744862095,
        "visibility": "PUBLIC",
        "publishedAt": 1703744862033,
        "author": "urn:li:organization:101414444",
        "id": "urn:li:share:7146023559452666882",
        "distribution": {
            "feedDistribution": "MAIN_FEED",
            "thirdPartyDistributionChannels": []
        },
        "commentary": "Hi Community!",
        "lifecycleStateInfo": {
            "isEditedByAuthor": false
        }
    }
]
}

在下一步中,我将使用 Parse JSON 来读取上面的 JSON,例如

在上图的架构输入中,我尝试从示例生成,它询问示例有效负载,我将上面的 JSON 放在其中,它生成了下面的架构。

{
"type": "object",
"properties": {
    "paging": {
        "type": "object",
        "properties": {
            "start": {
                "type": "integer"
            },
            "count": {
                "type": "integer"
            },
            "links": {
                "type": "array"
            },
            "total": {
                "type": "integer"
            }
        }
    },
    "elements": {
        "type": "array",
        "items": {
            "type": "object",
            "properties": {
                "isReshareDisabledByAuthor": {
                    "type": "boolean"
                },
                "createdAt": {
                    "type": "integer"
                },
                "lifecycleState": {
                    "type": "string"
                },
                "lastModifiedAt": {
                    "type": "integer"
                },
                "visibility": {
                    "type": "string"
                },
                "publishedAt": {
                    "type": "integer"
                },
                "author": {
                    "type": "string"
                },
                "id": {
                    "type": "string"
                },
                "distribution": {
                    "type": "object",
                    "properties": {
                        "feedDistribution": {
                            "type": "string"
                        },
                        "thirdPartyDistributionChannels": {
                            "type": "array"
                        }
                    }
                },
                "content": {
                    "type": "object",
                    "properties": {
                        "media": {
                            "type": "object",
                            "properties": {
                                "altText": {
                                    "type": "string"
                                },
                                "id": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                },
                "commentary": {
                    "type": "string"
                },
                "lifecycleStateInfo": {
                    "type": "object",
                    "properties": {
                        "isEditedByAuthor": {
                            "type": "boolean"
                        }
                    }
                }
            },
            "required": [
                "isReshareDisabledByAuthor",
                "createdAt",
                "lifecycleState",
                "lastModifiedAt",
                "visibility",
                "publishedAt",
                "author",
                "id",
                "distribution",
                "commentary",
                "lifecycleStateInfo"
            ]
            }
        }
    }
}

content 对象具有 media 值时,即成功运行

但是当content对象具有multiImage值时失败

所以,我不确定我们是否可以为上述 JSON 生成架构?或任何其他方法来解决上述问题。

json jsonschema power-automate
1个回答
0
投票

我认为这应该有效...

{
  "type": "object",
  "properties": {
    "paging": {
      "type": "object",
      "properties": {
        "start": {
          "type": "integer"
        },
        "count": {
          "type": "integer"
        },
        "links": {
          "type": "array"
        },
        "total": {
          "type": "integer"
        }
      }
    },
    "elements": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "isReshareDisabledByAuthor": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "integer"
          },
          "lifecycleState": {
            "type": "string"
          },
          "lastModifiedAt": {
            "type": "integer"
          },
          "visibility": {
            "type": "string"
          },
          "publishedAt": {
            "type": "integer"
          },
          "author": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "distribution": {
            "type": "object",
            "properties": {
              "feedDistribution": {
                "type": "string"
              },
              "thirdPartyDistributionChannels": {
                "type": "array"
              }
            }
          },
          "content": {
            "type": "object",
            "properties": {
              "media": {
                "type": "object",
                "properties": {
                  "altText": {
                    "type": "string"
                  },
                  "id": {
                    "type": "string"
                  }
                }
              },
              "multiImage": {
                "type": "object",
                "properties": {
                  "images": {
                    "type": "array",
                    "items": [
                      {
                        "type": "object",
                        "properties": {
                          "altText": {
                            "type": "string"
                          },
                          "id": {
                            "type": "string"
                          }
                        }
                      }
                    ]
                  }
                }
              }
            }
          },
          "commentary": {
            "type": "string"
          },
          "lifecycleStateInfo": {
            "type": "object",
            "properties": {
              "isEditedByAuthor": {
                "type": "boolean"
              }
            }
          }
        },
        "required": [
          "isReshareDisabledByAuthor",
          "createdAt",
          "lifecycleState",
          "lastModifiedAt",
          "visibility",
          "publishedAt",
          "author",
          "id",
          "distribution",
          "commentary",
          "lifecycleStateInfo"
        ]
      }
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.