[英]Add default field to Jolt JSON transformation
I'm trying to make a JSON transformation using JOLT and I think I'm close, but what I can't do is add in a new field to each one which doesn't currently appear. 我正在尝试使用JOLT进行JSON转换,我想我已经接近了,但是我不能做的是将一个新字段添加到当前未出现的每个字段中。
I have read quite a few tutorials and this code below is what I would have expected to have worked. 我已经阅读了很多教程,下面的代码正是我期望的。 However it doesn't seem to add in the new "Name" field.
但是,似乎没有在新的“名称”字段中添加。
{
"totalElements": 168,
"columns": {
"dimension": {
"id": "variables/daterangehour",
"type": "time"
},
"columnIds": [
"1"
]
},
"rows": [
{
"itemId": "119050300",
"value": "00:00 2019-06-03",
"data": [
120
]
},
{
"itemId": "119050805",
"value": "05:00 2019-06-08",
"data": [
98
]
},
{
"itemId": "119050923",
"value": "23:00 2019-06-09",
"data": [
172
]
}
]
}
This is my jolt: 这是我的震撼:
[
{
"operation": "default",
"spec": {
"name": "chart1"
}
},
{
"operation": "shift",
"spec": {
"rows": {
"*": {
"value": "[&1].date",
"data": {
"*": "[&2].data"
}
}
}
}
}
]
This was output: 输出为:
[ {
"date" : "00:00 2019-06-03",
"data" : 120
}, {
"date" : "05:00 2019-06-08",
"data" : 98
}, {
"date" : "23:00 2019-06-09",
"data" : 172
} ]
I wanted it to be like this though: 我希望它像这样:
[ {
"name" : "graph1",
"date" : "00:00 2019-06-03",
"data" : 120
}, {
"name" : "graph1",
"date" : "05:00 2019-06-08",
"data" : 98
}, {
"name" : "graph1",
"date" : "23:00 2019-06-09",
"data" : 172
} ]
Can anyone please tell me where I am going wrong? 谁能告诉我我要去哪里错了? Apparently default is used to add in a new item but it doesnt seem to do anything.
显然默认是用来添加新项目的,但是它似乎什么也没做。
You should put sth like this: "#chart1": "[&1].name"
Hash puts harcoded value and then you do not need operation default. 您应该这样输入:
"#chart1": "[&1].name"
哈希值放入了被编码的值,那么您不需要默认操作。 Or if you want to use operation default: 或者,如果您想使用默认操作:
[
{
"operation": "shift",
"spec": {
"rows": {
"*": {
"value": "[&1].date",
"data": {
"*": "[&2].data"
}
}
}
}
},
{
"operation": "default",
"spec": {
"*": {
"name": "chart1"
}
}
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.