由于标签不同而导致解析JSON的故障
我是JSON的新手,所以如果这是一个超级基本的问题,请忍受我。我正在使用Microsoft Power Automate/Flow来构建与传入JSON文件的流动。我在流程中放置了一个解析JSON控件,并使用了从进入的解决方案中导出的样本导出,并为我构建了架构,跑得很好,没有错误。当我有一个JSON文件的标签与该模式的标签不同时,问题出现了,因此我失败了。这是来自SurveyMonkey的,而导致我问题的领域未列入模式中。为我构建的架构看起来像这样:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"answers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"choice_id": {
"type": "string"
},
"simple_text": {
"type": "string"
}
},
"required": [
"choice_id",
"simple_text"
]
}
},
"family": {
"type": "string"
},
"subtype": {
"type": "string"
},
"heading": {
"type": "string"
}
},
"required": [
"id",
"answers",
"family",
"subtype",
"heading"
]
}
}
我得到的错误是“从对象中丢失了必需的属性:choice_id”。
对于出现的响应对此有评论的情况,标签是其他_id vs.Choice_id。有没有办法将JSON模式设置为将其他_ID视为可选标签并运行是否存在?
这是我正在使用的可选评论中的JSON文件的片段:
{
"choice_id": "10054397857",
"row_id": "10054397873",
"choice_metadata": {
"weight": "4"
},
"simple_text": "Fixed question answer"
},
{
"other_id": "10054397859",
"text": "open and optional comment",
"tag_data": [
{
"hexcolor": "F9BE00",
"label": "sm_neutral",
"tag_type": "sentiment"
}
],
"simple_text": "open and optional comment"
}
I am extremely new to JSON so please bear with me if this is a super basic question. I am using Microsoft Power Automate/Flow to build a flow dealing with an incoming JSON file. I placed a Parse JSON control in the flow and used a sample export from the solution coming in and the schema was built for me and ran just fine, no errors. The problem came up when I had a JSON file come in with a different tag than what the schema was looking for so it failed on me. This is from SurveyMonkey and the field that is causing me problems is not listed in the schema. The schema that was built for me looks like this:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"answers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"choice_id": {
"type": "string"
},
"simple_text": {
"type": "string"
}
},
"required": [
"choice_id",
"simple_text"
]
}
},
"family": {
"type": "string"
},
"subtype": {
"type": "string"
},
"heading": {
"type": "string"
}
},
"required": [
"id",
"answers",
"family",
"subtype",
"heading"
]
}
}
The error I get is "Required properties are missing from object: choice_id."
For the scenario that the response coming in has a comment on it, the tag is other_id vs. choice_id. Is there a way to set the JSON schema to see that other_id as an optional tag and run if it exists or not?
Here is a snippet of the JSON file that I am getting in with the optional comment:
{
"choice_id": "10054397857",
"row_id": "10054397873",
"choice_metadata": {
"weight": "4"
},
"simple_text": "Fixed question answer"
},
{
"other_id": "10054397859",
"text": "open and optional comment",
"tag_data": [
{
"hexcolor": "F9BE00",
"label": "sm_neutral",
"tag_type": "sentiment"
}
],
"simple_text": "open and optional comment"
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到了这个问题,只需要稍微更改JSON模式。请参阅下面的新示例模式,该模式正在使用多个测试。所需的更改添加了附加属性选项,将新元素添加到所需区域,并更改可选。
Found the issue and it just required changing the JSON Schema slightly. See below for the new sample Schema that is working with several tests against it. The changes required adding an additional properties option, adding a new element to the required area and changing required to optional.