gpt4 book ai didi

json - 什么 JSON 对关键字 'anyOf' 有效

转载 作者:行者123 更新时间:2023-12-04 04:49:44 26 4
gpt4 key购买 nike

我想知道是否有人可以举一个对使用“anyOf”关键字的模式有效的 JSON 示例?我正在尝试编写一些将在 python 中输出有效 JSON 的代码。

例如,如果您有一个如下所示的架构:

"anyOf": {
"category_0": {
"main": { "enum": ["learning"]},
"sub": { "enum": ["ADD/ADHD", "dyslexia", "general learning disability", "language disorder", "intellectual giftedness", "other"]}
},
"category_1": {
"main": { "enum": ["mental"]},
"sub": { "enum": ["down's syndrome", "asperger's syndrome", "autism", "other"]}
},
"category_2": {
"main": { "enum": ["behavioral"]}
},
"category_3": {
"main": { "enum": ["medical"]},
"sub": { "enum": ["diabetes", "allergies", "eating disorders", "chronic illness", "other"]}
},
"category_4": {
"main": { "enum": ["physical"]},
"sub": { "enum": ["blind", "deaf", "cerebral palsy", "other"]}
}
}

什么 JSON 是有效的?

我用来在 python 中输出 JSON 的代码是这样的:
main = row.get('main', [])
sub = row.get('sub',[])
category = dict(main = main, sub=sub)
special_needs = category

最佳答案

您的 JSON 无效,因为字符串不能位于最外面的数组或对象之外。

最低有效 JSON 如下所示:{} .您可以通过将您在此处显示的内容放入其中来使您的 JSON 有效:

{
"anyOf": {
"category_0": {
"main": {
"enum": [
"learning"
]
},
"sub": {
"enum": [
"ADD/ADHD",
"dyslexia",
"general learning disability",
"language disorder",
"intellectual giftedness",
"other"
]
}
},
"category_1": {
"main": {
"enum": [
"mental"
]
},
"sub": {
"enum": [
"down's syndrome",
"asperger's syndrome",
"autism",
"other"
]
}
},
"category_2": {
"main": {
"enum": [
"behavioral"
]
}
},
"category_3": {
"main": {
"enum": [
"medical"
]
},
"sub": {
"enum": [
"diabetes",
"allergies",
"eating disorders",
"chronic illness",
"other"
]
}
},
"category_4": {
"main": {
"enum": [
"physical"
]
},
"sub": {
"enum": [
"blind",
"deaf",
"cerebral palsy",
"other"
]
}
}
}
}

关于json - 什么 JSON 对关键字 'anyOf' 有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17618491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com