英文:
jolt transformation - array array inside apache nifi
问题
Unsuccessful attempt:
[
{
"operation": "shift",
"spec": {
"results": {
"*": {
"group.queueId": "[&].queueid",
"group.mediaType": "[&].mediatype",
"data": {
"*": {
"metric": "[&3].metric1",
"stats.count": "[&3].metric1_count"
}
}
}
}
}
}
]
Unsuccessful Output:
[
{
"queueid": "fila1",
"mediatype": "message1",
"metric1": [
"oInteracting1",
"oWaiting1"
],
"metric1_count": [
1,
0
]
},
{
"queueid": "fila2",
"mediatype": "message2",
"metric1": [
"oInteracting2",
"oWaiting2"
],
"metric1_count": [
8,
0
]
},
{
"queueid": "fila3",
"mediatype": "message3",
"metric1": [
"oInteracting3",
"oWaiting3"
],
"metric1_count": [
1,
0
]
}
]
Expected output:
[
{
"queueid": "fila1",
"mediatype": "message1",
"oInteracting1": 1,
"oWaiting1": 0
},
{
"queueid": "fila2",
"mediatype": "message2",
"oInteracting2": 8,
"oWaiting2": 0
},
{
"queueid": "fila3",
"mediatype": "message3",
"oInteracting3": 1,
"oWaiting3": 0
}
]
You can use the corrected spec to achieve the expected output. The issue with your previous attempt was in the spec, and the corrected spec should give you the desired result.
英文:
my attempts
Input :
{
"results": [
{
"group": {
"queueId": "fila1",
"mediaType": "message1"
},
"data": [
{
"metric": "oInteracting1",
"stats": {
"count": 1
},
"truncated": false
},
{
"metric": "oWaiting1",
"stats": {
"count": 0
}
}
]
},
{
"group": {
"queueId": "fila2",
"mediaType": "message2"
},
"data": [
{
"metric": "oInteracting2",
"stats": {
"count": 8
},
"truncated": false
},
{
"metric": "oWaiting2",
"stats": {
"count": 0
}
}
]
},
{
"group": {
"queueId": "fila3",
"mediaType": "message3"
},
"data": [
{
"metric": "oInteracting3",
"stats": {
"count": 1
},
"truncated": false
},
{
"metric": "oWaiting3",
"stats": {
"count": 0
}
}
]
}
]
}
Unsuccessful attempt :
[
{
"operation": "shift",
"spec": {
"results": {
"*": {
"@group.queueId": "[&].queueid",
"@group.mediaType": "[&].mediatype",
"data": {
"*": {
"@metric": "[&3].metric1",
"@stats.count": "[&3].metric1_count"
}
}
}
}
}
}
]
Unsuccessful Output :
[
{
"queueid": "fila1",
"mediatype": "message1",
"metric1": [
"oInteracting1",
"oWaiting1"
],
"metric1_count": [
1,
0
]
},
{
"queueid": "fila2",
"mediatype": "message2",
"metric1": [
"oInteracting2",
"oWaiting2"
],
"metric1_count": [
8,
0
]
},
{
"queueid": "fila3",
"mediatype": "message3",
"metric1": [
"oInteracting3",
"oWaiting3"
],
"metric1_count": [
1,
0
]
}
]
Expected output :
[
{
"queueid": "fila1",
"mediatype": "message1",
"oInteracting1": 1,
"oWaiting1": 0
},
{
"queueid": "fila2",
"mediatype": "message2",
"oInteracting1": 8,
"oWaiting1": 0
},
{
"queueid": "fila3",
"mediatype": "message3",
"oInteracting3": 1,
"oWaiting3": 0
}
]
Also trying to add the condition
"data": {"\*": { "stats.count": "metric"}}
but it didn't work
Thanks
答案1
得分: 1
只递归匹配**stats
**对象内部,例如
[
{
"operation": "shift",
"spec": {
"results": {
"*": {
"@group.queueId": "[&].queueid",
"@group.mediaType": "[&].mediatype",
"data": {
"*": {
"stats": {
"@count": "[&4].@2,metric" // 遍历: 和 {(2级)以达到其在JSON中的原始级别
}
}
}
}
}
}
}
]
该网站上的演示位于 http://jolt-demo.appspot.com/:
英文:
Just recursively match within the stats
object such as
[
{
"operation": "shift",
"spec": {
"results": {
"*": {
"@group.queueId": "[&].queueid",
"@group.mediaType": "[&].mediatype",
"data": {
"*": {
"stats": {
"@count": "[&4].@2,metric" // traverses : and { ( 2 levels ) to reach upto its original level within the JSON
}
}
}
}
}
}
}
]
the demo on the site http://jolt-demo.appspot.com/ is
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论