Hi all,
I am trying to read a json file, that contains a collection of objects. It is NOT an array, and the objects have no name, they have just a number. It’s that number I am interested in, but I can’t seem to find a way to get it exposed. My Json looks like this:
{
"1": {
"name": "msg_status",
"data": {
<snip>
},
"port": 4,
"timestamp": 1717497996,
"timestamp_parsed": "2024-06-04 12:46:36"
},
"2": {
"name": "msg_ublox_location",
"data": {
<snip>
},
"port": 2,
"timestamp": 1717498735,
"timestamp_parsed": "2024-06-04 12:58:55"
},
"3": {
"name": "msg_ublox_location_short",
"data": {
<snip>
},
"port": 13,
"timestamp": 1717498741,
"timestamp_parsed": "2024-06-04 12:59:01"
},
"4": {
"name": "msg_ublox_location",
"data": {
<snip>
},
"port": 2,
"timestamp": 1717499651,
"timestamp_parsed": "2024-06-04 13:14:11"
}
}
and so on, for a couple of thousand objects per file. The data{} part contains different attributes depending on the name attribute, that’s not important for this question because I can get those out without a problem.
My problem is the numbers 1 to 4 in this short example: I can’t seem get those into an attribute per feature. If I use a JSON Reader, with json
If I use json as JSON Query, II’ll get a single feature with thousands of attributes like this:
1.port
1.timestamp
1.timestamp_parsed
2.name
2.data.<snip>
2.port
2.timestamp
2.timestamp_parsed
etc….
In a relatively small file with only a week’s worth of data, this can go up to 4530.timestamp, and typically the data is harvested once every 3 weeks. I suppose I could use an AttributeExploder on this single feature, then process the attributename/value pairs, but that feels clumsy and a workaround. I’d much rather use a clever JSON Query, if that is possible.
I could also use a counter, but given the fact that typically I’d receive multiple files of data at a time, and the numbers are only unique per separate file, that also does not feel right. But I can’t seem to find anything about this type of Json, where the key-name is actually a value one needs.
Anybody have any ideas?
TIA,
Stefan