我想使用JoLT规范将对象包装到数组中,以便在NiFi中进一步使用。 但是我似乎无法找到解决方案。
假设我有这个json作为输入
{
"toIndex": [
{
"content": [
{
"firstName": "maxime",
"lastName": "g",
"toArray": {
"one": "fun",
"two": "funfun",
"three": "funfunfun"
}
}
]
},
{
"content": [
{
"firstName": "monica",
"lastName": "beluci",
"toArray": {
"one": "fun",
"two": "funfun",
"three": "funfunfun"
}
}
]
}
]
}
我非常想把它作为输出:
{
"toIndex": [
{
"content": [
{
"firstName": "maxime",
"lastName": "g",
"toArray": [ {
"one": "fun",
"two": "funfun",
"three": "funfunfun"
}]
}
]
},
{
"content": [
{
"firstName": "monica",
"lastName": "beluci",
"toArray": [{
"one": "fun",
"two": "funfun",
"three": "funfunfun"
}]
}
]
}
]
}
不幸的是我得到了这个输出:
{
"toIndex" : [ {
"content" : [ {
"firstName" : "maxime",
"lastName" : "g",
"toArray" : {
"one" : "fun",
"two" : "funfun",
"three" : "funfunfun"
}
}, {
"toArray" : [ {
"one" : "fun",
"two" : "funfun",
"three" : "funfunfun"
} ]
}, {
"firstName" : "monica",
"lastName" : "beluci",
"toArray" : {
"one" : "fun",
"two" : "funfun",
"three" : "funfunfun"
}
}, {
"toArray" : [ {
"one" : "fun",
"two" : "funfun",
"three" : "funfunfun"
} ]
} ]
} ]
}
我的(糟糕的)规格是这样的:
[{
"operation": "shift",
"spec": {
"toIndex": {
"*": {
"content": {
"*": {
"@": "toIndex[&1].content[]", // passthru
"toArray": "toIndex[&1].content[].toArray[]"
}
}
}
}
}
}
]
如果你们中的一位友善地指出我在做什么错...
谢谢。
答案 0 :(得分:0)
查看基数操作是否是您要查找的内容:
[
{
"operation": "cardinality",
"spec": {
"toIndex": {
"*": {
"content": {
"*": {
"toArray": "MANY"
}
}
}
}
}
}
]
输出
{
"toIndex" : [ {
"content" : [ {
"firstName" : "maxime",
"lastName" : "g",
"toArray" : [ {
"one" : "fun",
"two" : "funfun",
"three" : "funfunfun"
} ]
} ]
}, {
"content" : [ {
"firstName" : "monica",
"lastName" : "beluci",
"toArray" : [ {
"one" : "fun",
"two" : "funfun",
"three" : "funfunfun"
} ]
} ]
} ]
}