在给定的JSON输入中,主要对象是“Account”。目标是创建一个Jolt规范,只有在“Account”对象中不存在属性时,才有选择地从“SystemResponse”对象中选择属性。例如,如果“serviceFlag”存在于“SystemResponse”中,但不存在于“Account”中,则应将其添加到“Account”。但是,如果“Account”对象中已存在“resellerFlag”(Map到“Account”中的“isReseller”)等属性,则应忽略这些属性。
请帮助我实现这个有条件的属性选择。
Input.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
}
}
}
1条答案
按热度按时间lpwwtiir1#
您可以使用**
~
**运算符来处理此类问题。这意味着如果相应的属性不存在或为null,则与返回值匹配,例如在以下转换中应用网站http://jolt-demo.appspot.com/上的 demo 输入略有变化,如下所示: