使用 Jolt 从第一个数组元素中提取值
Extracting values from first array element with Jolt
我有以下 JSON 文档:
{
"pbid": 123,
"pid": 0,
"time": 1483551745000,
"timestamp": "2017-01-04 17:42:25",
"creationTime": 1483551789000,
"creationTimestamp": "2017-01-04 17:43:09",
"name": "myname",
"triggeredComponents": [
{
"device": {
"did": 20,
"ip": "127.0.0.1",
"firstSeen": 1427474095000,
"lastSeen": 1483545006000,
"typename": "dnsserver"
},
"time": 1483551789000
}
]
}
我需要使用 Jolt 将其转换为以下内容:
{
"event_id" : 123, ( pbid )
"name" : "myname", ( name )
"did": "20", ( triggeredComponents[0].device.did )
"first_seen": 1427474095000, ( triggeredComponents[0].device.firstSeen )
"last_seen": 1483545006000 ( triggeredComponents[0].device.lastSeen )
}
我可以接受基本的转换(event_id
和 name
),但我不知道如何从数组中提取。这是我目前的尝试(我也尝试过其他几种方法):
[
{
"operation": "shift",
"spec": {
"pbid": "event_id",
"name": "name",
"triggeredComponents" : {
"*": {
"did": "triggeredComponents[&1].device.did",
"first_seen": "triggeredComponents[&1].device.firstSeen",
"last_seen": "triggeredComponents[&1].device.lastSeen"
}
}
}
}
]
与供应商联系后发现 triggeredComponents
数组将只包含一个对象,因此我只需要查看第 0 个元素。
规格
[
{
"operation": "shift",
"spec": {
"pbid": "event_id",
"name": "name",
"triggeredComponents": {
"0": {
"device": {
"did": "did",
"firstSeen": "first_seen",
"lastSeen": "last_seen"
}
}
}
}
}
]
您错过了 "triggeredComponents[0]" 和 "did" 之间的 "device"。
我有以下 JSON 文档:
{
"pbid": 123,
"pid": 0,
"time": 1483551745000,
"timestamp": "2017-01-04 17:42:25",
"creationTime": 1483551789000,
"creationTimestamp": "2017-01-04 17:43:09",
"name": "myname",
"triggeredComponents": [
{
"device": {
"did": 20,
"ip": "127.0.0.1",
"firstSeen": 1427474095000,
"lastSeen": 1483545006000,
"typename": "dnsserver"
},
"time": 1483551789000
}
]
}
我需要使用 Jolt 将其转换为以下内容:
{
"event_id" : 123, ( pbid )
"name" : "myname", ( name )
"did": "20", ( triggeredComponents[0].device.did )
"first_seen": 1427474095000, ( triggeredComponents[0].device.firstSeen )
"last_seen": 1483545006000 ( triggeredComponents[0].device.lastSeen )
}
我可以接受基本的转换(event_id
和 name
),但我不知道如何从数组中提取。这是我目前的尝试(我也尝试过其他几种方法):
[
{
"operation": "shift",
"spec": {
"pbid": "event_id",
"name": "name",
"triggeredComponents" : {
"*": {
"did": "triggeredComponents[&1].device.did",
"first_seen": "triggeredComponents[&1].device.firstSeen",
"last_seen": "triggeredComponents[&1].device.lastSeen"
}
}
}
}
]
与供应商联系后发现 triggeredComponents
数组将只包含一个对象,因此我只需要查看第 0 个元素。
规格
[
{
"operation": "shift",
"spec": {
"pbid": "event_id",
"name": "name",
"triggeredComponents": {
"0": {
"device": {
"did": "did",
"firstSeen": "first_seen",
"lastSeen": "last_seen"
}
}
}
}
}
]
您错过了 "triggeredComponents[0]" 和 "did" 之间的 "device"。