任何想法如何获得一个Jolt规范的if-else条件



我有下面的Jolt,并且想把desc body放在"no"orwithout "no"取决于"yang:operation"中定义的delete操作。在Jolt下尝试,但看起来没有达到"\@desc"中定义的条件:

输入JSON

{
"ABC": [
{
"@desc": {
"yang:operation": "delete"
},
"desc": "attr1"
}
]
}

Jolt Spec提供

[
{
"operation": "shift",
"spec": {
"ABC": {
"*": {
"\@desc": {
"yang:operation": {
"#delete": {
"desc": "no.desc.\$\.DESC.\.DESC"
},
"*": {
"desc": "desc.\$\.DESC.\.DESC"
}
}
},
"desc": "desc.\$\.DESC.\.DESC"
}
}
}
}
]

预期输出

{
"no" : {
"desc" : {
"$.DESC" : {
".DESC" : "attr1"
}
}
}
}

确实你是如此接近解决方案,只是最内层的desc键应该用#通配符限定,例如。#desc;而不是最高级别的delete

因此,您可以使用以下规范重试:
[
{
"operation": "shift",
"spec": {
"ABC": {
"*": {
"\@desc": {
"yang:operation": {
"delete": {
"#desc": "no.desc.\$\.DESC.\.DESC"
},
"*": {
"#desc": "desc.\$\.DESC.\.DESC"
}
}
}
}
}
}
}
]

和外层(第二个)"desc": "desc.\$\.DESC.\.DESC"似乎没有意义,只是删除它。

最新更新