在给定的 JSON 输入中,主要对象是“Account”。目标是创建一个 Jolt 规范,仅当“Account”对象中尚不存在这些属性时,该规范才会有选择地从“SystemResponse”对象中选取属性。例如,如果“serviceFlag”存在于“SystemResponse”中但不存在于“Account”中,则应将其添加到“Account”中。但是,如果“resellerFlag”(映射到“Account”中的“isReseller”)等属性和其他属性已存在于“Account”对象中,则应忽略它们。
请帮助我实现这个有条件的房产选择。
输入.json
{
"Account": {
"AccountInfo": {
"isReseller": 10,
"poRequired": 10
}
},
"SystemResponse": {
"resellerFlag": "false",
"poRequiredFlag": "false",
"serviceFlag": "true"
}
}
输出.json
[
{
"operation": "shift",
"spec": {
"Account": {
"AccountInfo": {
"*": "Account.AccountInfo.&"
}
},
"SystemResponse": {
"@resellerFlag": {
"false": {
// Check if isReseller doesn't already exist in Account
"Account.AccountInfo.isReseller": {
"#0": "partyAccount.eqxAccountInfo.isReseller"
}
}
},
"poRequiredFlag": {
"false": {
// Check if poRequired doesn't already exist in Account
"@Account.AccountInfo.poRequired": {
"#0": "Account.AccountInfo.poRequired"
}
}
},
"serviceFlag": {
"false": {
// Check if poRequired doesn't already exist in Account
"@Account.AccountInfo.isService": {
"#0": "Account.AccountInfo.isService"
}
},
"true": {
// Check if poRequired doesn't already exist in Account
"@Account.AccountInfo.isService": {
"#1": "Account.AccountInfo.isService"
}
}
}
}
}
}
]
实际产量
{
"Account" : {
"AccountInfo" : {
"isReseller" : 10,
"poRequired" : 10
}
}
}
预期输出json
{
"Account" : {
"AccountInfo" : {
"isReseller" : 10,
"poRequired" : 10,
"isService" : 1
}
}
}
您可以使用
~
运算符来处理此类问题。这意味着如果相应的属性不存在或为空,则与应用的返回值匹配,例如在以下转换中
[
{
"operation": "modify-overwrite-beta",
"spec": {
"Account": {
"AccountInfo": {
"~isReseller": "@(3,SystemResponse.resellerFlag)",
"~poRequired": "@(3,SystemResponse.poRequiredFlag)",
"~serviceFlag": "@(3,SystemResponse.serviceFlag)"
}
}
}
},
{
"operation": "shift",
"spec": {
"Account": {
"AccountInfo": {
"*": {
"true": {
"#1": "&4.&3.&2"
},
"false": {
"#0": "&4.&3.&2"
},
"*": { // leave the rest as they are
"@1": "&4.&3.&2"
}
}
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"Account": {
"AccountInfo": {
"*": "=toInteger" // convert quoted integers unquoted
}
}
}
}
]