JOLT 仅从数组中的数组中获取一个值
JOLT get only one value from an array inside an array
我一直在尝试找出如何从我的事件数组中的数组中获取第一个值 JSON。
我想我必须对 Cardinality 做点什么,但我不太明白所以任何帮助将不胜感激。
这就是我的 JSON 的样子
{
"rootid": "19718",
"clloadm": "2021-06-01T22:40:02",
"clload": "2021-06-01T21:21:39",
"date": "2021-05-25T21:52:30",
"events": [
{
"done": {
"id": "e0",
"value": "2021-05-29T08:08:19"
},
"id": "e0_event",
"started": {
"id": "e0",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e1",
"value": "2021-05-27T02:20:25"
},
"id": "e1_event",
"started": {
"id": "e1",
"value": "2021-05-27T02:20:25"
},
"status": "complete"
},
{
"done": {
"id": "e2",
"value": "2021-05-29T08:08:19"
},
"id": "e2_event",
"started": {
"id": "e2",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e3",
"value": "2021-05-29T08:08:19"
},
"id": "e3_event",
"started": {
"id": "e3",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e4",
"value": "2021-05-29T08:08:19"
},
"id": "e4_event",
"started": {
"id": "e4",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
}
],
"ids": [
{
"id": "id",
"source": "source",
"value": "value"
}
]
}
我的 Jolt 规格
[
{
"operation": "shift",
"spec": {
"*": "&",
"events": {
"*": {
"*": {
"@id": {
"e0": { "@(2,value)": "&" },
"e4": { "@(2,value)": "&" }
}
}
}
},
"ids": {
"*": {
"@value": "@id"
}
}
}
}
]
我得到的结果:
{
"rootid" : "19718",
"clloadm" : "2021-06-01T22:40:02",
"clload" : "2021-06-01T21:21:39",
"date" : "2021-05-25T21:52:30",
"e0" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"e4" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"id" : "value",
"new_id" : "value"
}
我希望结果更像这样,其中只选择了第一个值:
{
"rootid" : "19718",
"clloadm" : "2021-06-01T22:40:02",
"clload" : "2021-06-01T21:21:39",
"date" : "2021-05-25T21:52:30",
"e0" : "2021-05-29T08:08:19",
"e4" : "2021-05-29T08:08:19",
"id" : "value",
"new_id" : "value"
}
编辑:
我已经尝试将基数添加到我的规范中,但我似乎无法获得我想要的结果。
[
{
"operation": "shift",
"spec": {
"*": "&",
"events": {
"*": {
"*": {
"@id": {
"e0": { "@(2,value)": "&" },
"e4": {
"operation": "cardinality",
"spec": {
"e4": "ONE"
}
}
}
}
}
},
"ids": {
"*": {
"@value": "@id"
}
}
}
}
]
是的,您只需添加一个基数转换,例如
{
"operation": "cardinality",
"spec": {
"*": "ONE"
}
}
或者可选地使用 e* 通配符来限制以字母 e 开头的键的数组的结果,例如
{
"operation": "cardinality",
"spec": {
"e*": "ONE"
}
}
编辑:只需添加到当前规范。因此,您可以使用以下内容:
[
{
"operation": "shift",
"spec": {
"*": "&",
"events": {
"*": {
"*": {
"@id": {
"e0": {
"@(2,value)": "&"
},
"e4": {
"@(2,value)": "&"
}
}
}
}
},
"ids": {
"*": {
"@value": "@id"
}
}
}
},
{
"operation": "cardinality",
"spec": {
"e*": "ONE"
}
}
]
我一直在尝试找出如何从我的事件数组中的数组中获取第一个值 JSON。
我想我必须对 Cardinality 做点什么,但我不太明白所以任何帮助将不胜感激。
这就是我的 JSON 的样子
{
"rootid": "19718",
"clloadm": "2021-06-01T22:40:02",
"clload": "2021-06-01T21:21:39",
"date": "2021-05-25T21:52:30",
"events": [
{
"done": {
"id": "e0",
"value": "2021-05-29T08:08:19"
},
"id": "e0_event",
"started": {
"id": "e0",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e1",
"value": "2021-05-27T02:20:25"
},
"id": "e1_event",
"started": {
"id": "e1",
"value": "2021-05-27T02:20:25"
},
"status": "complete"
},
{
"done": {
"id": "e2",
"value": "2021-05-29T08:08:19"
},
"id": "e2_event",
"started": {
"id": "e2",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e3",
"value": "2021-05-29T08:08:19"
},
"id": "e3_event",
"started": {
"id": "e3",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
},
{
"done": {
"id": "e4",
"value": "2021-05-29T08:08:19"
},
"id": "e4_event",
"started": {
"id": "e4",
"value": "2021-05-29T08:08:19"
},
"status": "complete"
}
],
"ids": [
{
"id": "id",
"source": "source",
"value": "value"
}
]
}
我的 Jolt 规格
[
{
"operation": "shift",
"spec": {
"*": "&",
"events": {
"*": {
"*": {
"@id": {
"e0": { "@(2,value)": "&" },
"e4": { "@(2,value)": "&" }
}
}
}
},
"ids": {
"*": {
"@value": "@id"
}
}
}
}
]
我得到的结果:
{
"rootid" : "19718",
"clloadm" : "2021-06-01T22:40:02",
"clload" : "2021-06-01T21:21:39",
"date" : "2021-05-25T21:52:30",
"e0" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"e4" : [ "2021-05-29T08:08:19", "2021-05-29T08:08:19" ],
"id" : "value",
"new_id" : "value"
}
我希望结果更像这样,其中只选择了第一个值:
{
"rootid" : "19718",
"clloadm" : "2021-06-01T22:40:02",
"clload" : "2021-06-01T21:21:39",
"date" : "2021-05-25T21:52:30",
"e0" : "2021-05-29T08:08:19",
"e4" : "2021-05-29T08:08:19",
"id" : "value",
"new_id" : "value"
}
编辑: 我已经尝试将基数添加到我的规范中,但我似乎无法获得我想要的结果。
[
{
"operation": "shift",
"spec": {
"*": "&",
"events": {
"*": {
"*": {
"@id": {
"e0": { "@(2,value)": "&" },
"e4": {
"operation": "cardinality",
"spec": {
"e4": "ONE"
}
}
}
}
}
},
"ids": {
"*": {
"@value": "@id"
}
}
}
}
]
是的,您只需添加一个基数转换,例如
{
"operation": "cardinality",
"spec": {
"*": "ONE"
}
}
或者可选地使用 e* 通配符来限制以字母 e 开头的键的数组的结果,例如
{
"operation": "cardinality",
"spec": {
"e*": "ONE"
}
}
编辑:只需添加到当前规范。因此,您可以使用以下内容:
[
{
"operation": "shift",
"spec": {
"*": "&",
"events": {
"*": {
"*": {
"@id": {
"e0": {
"@(2,value)": "&"
},
"e4": {
"@(2,value)": "&"
}
}
}
}
},
"ids": {
"*": {
"@value": "@id"
}
}
}
},
{
"operation": "cardinality",
"spec": {
"e*": "ONE"
}
}
]