I have a JSON formatted payload with nested arrays that I want to modify into a simpler array. Input looks like this:
[{
"pim_network": [{
"addresses": [{
"ifindex": 1,
"ifname": "lo",
"address": "00:00:00:00:00:00",
"broadcast": "00:00:00:00:00:00",
"addr_info": [{
"family": "inet",
"local": "127.0.0.1",
"prefixlen": 8,
"label": "lo",
}, {
"family": "inet6",
"local": "::1",
"prefixlen": 128,
}]
}, {
"ifindex": 2,
"ifname": "ens33",
"address": "00:0c:29:02:b8:cd",
"broadcast": "ff:ff:ff:ff:ff:ff",
"addr_info": [{
"family": "inet",
"local": "192.168.119.129",
"prefixlen": 24,
"broadcast": "192.168.119.255",
"label": "ens33",
}, {
"family": "inet6",
"local": "fe80::20c:29ff:fe02:b8cd",
"prefixlen": 64,
}]
}, {
"ifindex": 3,
"ifname": "docker0",
"address": "02:42:36:ae:50:55",
"broadcast": "ff:ff:ff:ff:ff:ff",
"addr_info": [{
"family": "inet",
"local": "172.17.0.1",
"prefixlen": 16,
"broadcast": "172.17.255.255",
"label": "docker0",
}]
}]
}]
}]
Desired output is (some key:value pairs are used twice for the same MAC-adress for ipv4 and ipv6 data):
[{
"pim_network": [
{
"ifindex": 1,
"ifname": "lo",
"address": "00:00:00:00:00:00",
"broadcast": "00:00:00:00:00:00",
"family": "inet",
"local": "127.0.0.1",
"prefixlen": 8,
"label": "lo",
},
{
"ifindex": 1,
"ifname": "lo",
"address": "00:00:00:00:00:00",
"broadcast": "00:00:00:00:00:00",
"family": "inet6",
"local": "::1",
"prefixlen": 128,
},
{
"ifindex": 2,
"ifname": "ens33",
"address": "00:0c:29:02:b8:cd",
"broadcast": "ff:ff:ff:ff:ff:ff",
"family": "inet",
"local": "192.168.119.129",
"prefixlen": 24,
"broadcast": "192.168.119.255",
"label": "ens33",
},
{
"ifindex": 2,
"ifname": "ens33",
"address": "00:0c:29:02:b8:cd",
"broadcast": "ff:ff:ff:ff:ff:ff",
"family": "inet6",
"local": "fe80::20c:29ff:fe02:b8cd",
"prefixlen": 64,
},
{
"ifindex": 3,
"ifname": "docker0",
"address": "02:42:36:ae:50:55",
"broadcast": "ff:ff:ff:ff:ff:ff",
"family": "inet",
"local": "172.17.0.1",
"prefixlen": 16,
"broadcast": "172.17.255.255",
"label": "docker0",
}
]
}]
(Not working) spec so far:
[{
"operation": "shift",
"spec": {
"*": {
"*": "&",
"pim_network": {
"*": {
"addresses": {
"*": {
"address": "pim_network.[&1].address",
"addr_info": {
"*": {
"local": "pim_network.[&1].address.local"
}
}
}
}
}
}
}
}
}]
But then we get output like this:
"pim_network": [{
"address": "00:00:00:00:00:00"
}, {
"address": [{
"local": "::1"
}, "00:0c:29:02:b8:cd"]
}, {
"address": "02:42:36:ae:50:55"
}, {
"address": "02:42:aa:97:1e:97"
}, {
We have been struggling to find easy to understand documentation regarding using & (and other lookup functions) in JOLT transformations, but most sites we found are too abstract or assume a deeper knowledge of JOLT. If anybody knows a good site with good tutorials or an online course, please let me know. Me and my colleagues are advanced scripters, but that appears not to be enough to grasp the intricacies of JOLT easily.