这是一个简单的问题,我是 nifi 和 jolt 的新手。我只是想知道,如何在使用通配符时遍历 jolt 规范。例如,这是 jolt 演示站点中的示例,
输入是
{
"data": {
"1234": {
"clientId": "12",
"hidden": true
},
"1235": {
"clientId": "35",
"hidden": false
}
}
}
规范为
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"hidden": {
"true": {
// if hidden is true, then write the value disabled to the RHS output path
// Also @(3,clientId) means lookup the tree 3 levels, to the "1234" or "1235" level,
// and then come back down down the tree and grabe the value of "clientId"
"#disabled": "clients.@(3,clientId)"
},
"false": {
"#enabled": "clients.@(3,clientId)"
}
}
}
}
}
}
]
输出是
{
"clients" : {
"12" : "disabled",
"35" : "enabled"
}
}
我们是如何得到上面的输出的?就像 @(3,clientsid) 一样。据我所知,它上升了 3 个级别。但是 3 个级别相对于什么......规范或输入?无论哪种方式,如何向上移动 3 个级别,您能在这里定义哪些级别吗?
提前致谢
最佳答案
只需向后计算每个左大括号({
)或冒号(:
)的数量即可。每当它们不独立时,例如 :{
,则将其计为只有一个,以便到达目标键,即 "*"
在本例中,通配符位于 "data"
键下,对于 @(3,clientId)
;第一级是跨越 "#disabled"
或 "#enabled"
旁边的冒号 (:
),第二级是跨越左大括号在每个 bool 键旁边,然后第三级是在 "hidden"
键后面交叉左大括号,以到达具有 "data"
的对象的索引关键。
关于json - 我们如何遍历震动规范?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69805887/