gpt4 book ai didi

jolt - 如果值不存在则设置为 null,否则如果在 jolt 中存在则返回现有值

转载 作者:行者123 更新时间:2023-12-05 01:14:00 26 4
gpt4 key购买 nike

如示例输入所示,我在每个对象中都有扩展数组。当扩展名不包含 subscription-type 时,输出应为空,如输出所示,否则应包含现有值。同样适用于language-typesubscription-typelanguage-type 的顺序本质上是随机的。

我试过 spec 但它不起作用

  {
"operation": "modify-define-beta",
"spec": {
"*": {
"subscriptionType": {
"url": {
"myCoercedValue": "subscription-type",
"myStringValue": "subscription-type"
},
"value": {
"myCoercedValue": null,
"myStringValue": null
}
},
"languageType": {
"url": {
"myCoercedValue": "language-type",
"myStringValue": "language-type"
},
"value": {
"myCoercedValue": null,
"myStringValue": null
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"extension": "[&1].extension",
"subscriptionType": "[&1].extension[]",
"languageType": "[&1].extension[]"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"extension": {
"*": {
"@url": {
"myStringValue": {
"subscription-type": {
"@(3,value.myStringValue)": "[&3].subscriptionType[]"
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"0": "[]"
}
}
]

输入:

[
{
"extension": []
},
{
"extension": [
{
"url": {
"myCoercedValue": "subscription-type",
"myStringValue": "subscription-type"
},
"value": {
"myCoercedValue": "free",
"myStringValue": "free"
},
"extension": []
}
]
},
{
"extension": [
{
"url": {
"myCoercedValue": "language-type",
"myStringValue": "language-type"
},
"value": {
"myCoercedValue": "en-us",
"myStringValue": "en-us"
}
},
{
"url": {
"myCoercedValue": "subscription-type",
"myStringValue": "subscription-type"
},
"value": {
"myCoercedValue": "free",
"myStringValue": "free"
}
}
]
}
]

输出:

[ {
"subscriptionType" : [ null, "free", "free" ],
"language":[null,null,"en-US"]
} ]

最佳答案

或许你想要得到这样的结果?请尝试这些规范并说出您想要修改的内容。

[
{
"operation": "shift",
"spec": {
"*": {
"extension": {
"*": {
"url": {
"myCoercedValue": {
"subscription-type": {
"@(3,value)": {
"myCoercedValue": "subscriptionType[#8]"
}
},
"language-type": {
"@(3,value)": {
"myCoercedValue": "language[#8]"
}
}
}
}
}
}
}
}
}
]

关于jolt - 如果值不存在则设置为 null,否则如果在 jolt 中存在则返回现有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57392505/

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