gpt4 book ai didi

jolt - 检查 jolt 中是否为 null 或为空,并放入输入 JSON 中存在的另一个值

转载 作者:行者123 更新时间:2023-12-02 20:43:14 25 4
gpt4 key购买 nike

这是我的输入 JSON:

{
"AddressBilling": {
"FirstName": "Some Name",
"LastName": "Some Name",
"Address":"some address"
}
"AddressShipping": {
"FirstName": "",
"LastName": "",
"Address":""
}
}

我想保留“AddressBilling”和“AddressShipping”,但使用不同的名称,即“payment_address”和“shipping_address”,为此我为 payment_address 部分编写了规范文件

{
"operation": "shift",
"spec": {
"AddressBilling": {
"FirstName": "payment_address.firstname",
"LastName": "payment_address.lastname",
"Address": "payment_address.address"
},
"AddressShipping": {
"FirstName": "shipping_address.firstname",
"LastName": "shipping_address.lastname"

}
}
}

现在我想要检查“AddressShipping”对象中的“Address”键是否为空,然后我想将“AddressBilling”的“Address”复制到“shipping_address”的“Address”。

最佳答案

可以用“modify-default”来做到这一点。 Modify-default 只会在键不存在或它的值为空时填充一个值。

规范

[
{
"operation": "modify-default-beta",
"spec": {
"shipping_address": {
"address": "@(2,payment_address.address)"
}
}
}
]

输入A,没有送货地址

{
"payment_address": {
"address": "some address"
},
"shipping_address": {}
}

生成输出 A,其中复制了帐单地址

{
"payment_address" : {
"address" : "some address"
},
"shipping_address" : {
"address" : "some address"
}
}

输入B,其中有一个shipping_address

{
"payment_address": {
"address": "some address"
},
"shipping_address": {
"address": 1234
}
}

生成输出 B,其中送货地址不会被覆盖。

{
"payment_address" : {
"address" : "some address"
},
"shipping_address" : {
"address" : 1234
}
}

关于jolt - 检查 jolt 中是否为 null 或为空,并放入输入 JSON 中存在的另一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45411165/

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