json 到 json 的 Jolt 转换删除键值并添加拆分字符串值
Jolt transform for json to json remove key value and add split string value
我需要使用 jolt transform 来进行下面的 JSON 转换:
需要删除密钥:
src-port
和 tx-interval
要更改键的名称:
vdevice-host-name
到 local-host-name
在key:value处拆分key的字符串值vdevice-datakey
:
例子:
"vdevice-dataKey":"10.127.200.1-mpls-10.157.96.2-internet-ipsec"
至
"remote-system-ip : 10.157.96.2"
和 "remote-color" : "internet"
输入JSON是:
{
"data": [{
"src-ip": "10.161.25.170",
"dst-ip": "10.161.25.182",
"vdevice-name": "10.127.200.1",
"color": "mpls",
"src-port": 12346,
"createTimeStamp": 1623334401569,
"system-ip": "10.157.96.2",
"dst-port": 12346,
"site-id": 141011085,
"transitions": 0,
"local-host-name": "AEXI630_XITO098_E_COUNTRY_2081",
"local-color": "mpls",
"detect-multiplier": "7",
"vdevice-dataKey": "10.127.200.1-mpls-10.157.96.2-internet-ipsec",
"@rid": 168682,
"vmanage-system-ip": "10.127.200.1",
"proto": "ipsec",
"lastupdated": 1623334401562,
"state": "up",
"tx-interval": 1000,
"uptime-date": 1623334260000
}, {
"src-ip": "10.161.25.170",
"dst-ip": "10.162.45.94",
"vdevice-name": "10.127.200.1",
"color": "mpls",
"src-port": 12346,
"createTimeStamp": 1623334402985,
"system-ip": "10.157.16.2",
"dst-port": 12346,
"site-id": 142011050,
"transitions": 0,
"vdevice-host-name": "AEXI630_XITO098_E_COUNTRY_2081",
"local-color": "mpls",
"detect-multiplier": "7",
"vdevice-dataKey": "10.127.200.1-mpls-10.157.16.2-internet-ipsec",
"@rid": 206290,
"vmanage-system-ip": "10.127.200.1",
"proto": "ipsec",
"lastupdated": 1623334401562,
"state": "up",
"tx-interval": 1000,
"uptime-date": 1623334260000
}]
}
输出JSON是:
{
"data": [{
"src-ip": "10.161.25.170",
"dst-ip": "10.161.25.182",
"vdevice-name": "10.127.200.1",
"color": "mpls",
"createTimeStamp": 1623334401569,
"system-ip": "10.157.96.2",
"dst-port": 12346,
"site-id": 141011085,
"transitions": 0,
"local-host-name": "AEXI630_XITO098_E_COUNTRY_2081",
"local-color": "mpls",
"detect-multiplier": "7",
"vdevice-dataKey": "10.127.200.1-mpls-10.157.96.2-internet-ipsec",
"@rid": 168682,
"vmanage-system-ip": "10.127.200.1",
"proto": "ipsec",
"lastupdated": 1623334401562,
"state": "up",
"uptime-date": 1623334260000,
"remote-system-ip":"10.157.96.2",
"remote-color":"internet"
}, {
"src-ip": "10.161.25.170",
"dst-ip": "10.162.45.94",
"vdevice-name": "10.127.200.1",
"color": "mpls",
"createTimeStamp": 1623334402985,
"system-ip": "10.157.16.2",
"dst-port": 12346,
"site-id": 142011050,
"transitions": 0,
"local-host-name": "AEXI630_XITO098_E_COUNTRY_2081",
"local-color": "mpls",
"detect-multiplier": "7",
"vdevice-dataKey": "10.127.200.1-mpls-10.157.16.2-internet-ipsec",
"@rid": 206290,
"vmanage-system-ip": "10.127.200.1",
"proto": "ipsec",
"lastupdated": 1623334401562,
"state": "up",
"uptime-date": 1623334260000,
"remote-system-ip":"10.157.16.2",
"remote-color":"internet"
}]
}
您可以连续应用shift变换以生成要渲染的新元素,然后modify-overwrite-beta变换依次将字符串分成几部分以确定 remote-system-ip 和 remote-color 值,然后 remove 转换以删除所需的键以及最近生成的键,例如
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"vdevice-host-name": "&2.[&1].local-host-name",
"local-host-name": "&2.[&1].&",
"*": "&2.[&1].&",
"@(0,vdevice-dataKey)": "&2.[&1].remote"
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"remote": "=split('-', @(1,&))",
"remote-system-ip": "@(1,remote[2])",
"remote-color": "@(1,remote[3])"
}
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"*": {
"src-port": "",
"tx-interval": "",
"remote": ""
}
}
}
}
]
我需要使用 jolt transform 来进行下面的 JSON 转换:
需要删除密钥:
src-port
和 tx-interval
要更改键的名称:
vdevice-host-name
到 local-host-name
在key:value处拆分key的字符串值vdevice-datakey
:
例子:
"vdevice-dataKey":"10.127.200.1-mpls-10.157.96.2-internet-ipsec"
至
"remote-system-ip : 10.157.96.2"
和 "remote-color" : "internet"
输入JSON是:
{
"data": [{
"src-ip": "10.161.25.170",
"dst-ip": "10.161.25.182",
"vdevice-name": "10.127.200.1",
"color": "mpls",
"src-port": 12346,
"createTimeStamp": 1623334401569,
"system-ip": "10.157.96.2",
"dst-port": 12346,
"site-id": 141011085,
"transitions": 0,
"local-host-name": "AEXI630_XITO098_E_COUNTRY_2081",
"local-color": "mpls",
"detect-multiplier": "7",
"vdevice-dataKey": "10.127.200.1-mpls-10.157.96.2-internet-ipsec",
"@rid": 168682,
"vmanage-system-ip": "10.127.200.1",
"proto": "ipsec",
"lastupdated": 1623334401562,
"state": "up",
"tx-interval": 1000,
"uptime-date": 1623334260000
}, {
"src-ip": "10.161.25.170",
"dst-ip": "10.162.45.94",
"vdevice-name": "10.127.200.1",
"color": "mpls",
"src-port": 12346,
"createTimeStamp": 1623334402985,
"system-ip": "10.157.16.2",
"dst-port": 12346,
"site-id": 142011050,
"transitions": 0,
"vdevice-host-name": "AEXI630_XITO098_E_COUNTRY_2081",
"local-color": "mpls",
"detect-multiplier": "7",
"vdevice-dataKey": "10.127.200.1-mpls-10.157.16.2-internet-ipsec",
"@rid": 206290,
"vmanage-system-ip": "10.127.200.1",
"proto": "ipsec",
"lastupdated": 1623334401562,
"state": "up",
"tx-interval": 1000,
"uptime-date": 1623334260000
}]
}
输出JSON是:
{
"data": [{
"src-ip": "10.161.25.170",
"dst-ip": "10.161.25.182",
"vdevice-name": "10.127.200.1",
"color": "mpls",
"createTimeStamp": 1623334401569,
"system-ip": "10.157.96.2",
"dst-port": 12346,
"site-id": 141011085,
"transitions": 0,
"local-host-name": "AEXI630_XITO098_E_COUNTRY_2081",
"local-color": "mpls",
"detect-multiplier": "7",
"vdevice-dataKey": "10.127.200.1-mpls-10.157.96.2-internet-ipsec",
"@rid": 168682,
"vmanage-system-ip": "10.127.200.1",
"proto": "ipsec",
"lastupdated": 1623334401562,
"state": "up",
"uptime-date": 1623334260000,
"remote-system-ip":"10.157.96.2",
"remote-color":"internet"
}, {
"src-ip": "10.161.25.170",
"dst-ip": "10.162.45.94",
"vdevice-name": "10.127.200.1",
"color": "mpls",
"createTimeStamp": 1623334402985,
"system-ip": "10.157.16.2",
"dst-port": 12346,
"site-id": 142011050,
"transitions": 0,
"local-host-name": "AEXI630_XITO098_E_COUNTRY_2081",
"local-color": "mpls",
"detect-multiplier": "7",
"vdevice-dataKey": "10.127.200.1-mpls-10.157.16.2-internet-ipsec",
"@rid": 206290,
"vmanage-system-ip": "10.127.200.1",
"proto": "ipsec",
"lastupdated": 1623334401562,
"state": "up",
"uptime-date": 1623334260000,
"remote-system-ip":"10.157.16.2",
"remote-color":"internet"
}]
}
您可以连续应用shift变换以生成要渲染的新元素,然后modify-overwrite-beta变换依次将字符串分成几部分以确定 remote-system-ip 和 remote-color 值,然后 remove 转换以删除所需的键以及最近生成的键,例如
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"vdevice-host-name": "&2.[&1].local-host-name",
"local-host-name": "&2.[&1].&",
"*": "&2.[&1].&",
"@(0,vdevice-dataKey)": "&2.[&1].remote"
}
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"remote": "=split('-', @(1,&))",
"remote-system-ip": "@(1,remote[2])",
"remote-color": "@(1,remote[3])"
}
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"*": {
"src-port": "",
"tx-interval": "",
"remote": ""
}
}
}
}
]