我想创建一个 JOLT 规范来过滤掉我需要的一切。
我有这个 JSON 输入:
{
"StationDataList": {
"StationData": {
"ChannelData": [
{
"Values": {
"VT": [
{
"t": "2023-12-13T00:15:00",
"content": -1
},
{
"t": "2023-12-13T00:30:00",
"content": -2
},
{
"t": "2023-12-13T00:45:00",
"content": -3
}
]
},
"channelId": "channelId1"
},
{
"Values": {
"VT": [
{
"t": "2023-12-13T01:00:00",
"content": 1
},
{
"t": "2023-12-13T02:00:00",
"content": 2.5
},
{
"t": "2023-12-13T03:00:00",
"content": 3
}
]
},
"channelId": "channelId2"
}
],
"timezone": "+01:00",
"name": "stationName",
"stationId": "123"
}
}
}
我想将每个 VT 对象提取到单独的对象中,并将字段 stationId、channelId、name 和 timezone 包含到每个对象中。
我昨天尝试了一整天,有很多不同的规格,但没有一个能提供我需要的输出。 目前我有这个规格:
[
{
"operation": "shift",
"spec": {
"StationDataList": {
"StationData": {
"ChannelData": {
"*": {
"Values": {
"VT": {
"*": {
"@(5,stationId)": "[&4].stationId",
"@(5,timezone)": "[&4].timezone",
"@(5,name)": "[&4].name",
"@(3,channelId)": "[&4].channelId",
"t": "[&4].t",
"content": "[&4].content"
}
}
}
}
}
}
}
}
}
]
它返回我这个输出:
[ {
"stationId" : [ "123", "123", "123" ],
"timezone" : [ "+01:00", "+01:00", "+01:00" ],
"name" : [ "stationName", "stationName", "stationName" ],
"channelId" : [ "channelId1", "channelId1", "channelId1" ],
"t" : [ "2023-12-13T00:15:00", "2023-12-13T00:30:00", "2023-12-13T00:45:00" ],
"content" : [ -1, -2, -3 ]
}, {
"stationId" : [ "123", "123", "123" ],
"timezone" : [ "+01:00", "+01:00", "+01:00" ],
"name" : [ "stationName", "stationName", "stationName" ],
"channelId" : [ "channelId2", "channelId2", "channelId2" ],
"t" : [ "2023-12-13T01:00:00", "2023-12-13T02:00:00", "2023-12-13T03:00:00" ],
"content" : [ 1, 2.5, 3 ]
} ]
但我希望它们都是单独的对象,而不是全部在一个数组中,例如:
{
"stationId" : "123",
"timezone" : "+01:00",
"name" : "stationName",
"channelId" : "channelId1",
"t" : "2023-12-13T00:15:00",
"content" : -1
},
{
"stationId" : "123",
"timezone" : "+01:00",
"name" : "stationName",
"channelId" : "channelId1",
"t" : "2023-12-13T00:30:00",
"content" : -2
}
...
我怎样才能做到这一点?为什么他将所有内容添加到数组中而不是创建单独的对象?将不胜感激任何帮助。
由于 JSON 格式限制,没有数组包装器的独立对象是不可能的,但是如果需要将输出作为对象数组,那么您应该通过两个数组的索引来分隔对象层:
ChannelData
和VT
,例如作为
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": {
"*": {
"*": {
"VT": {
"*": {
"@5,stationId": "&4_&1.stationId",
"@5,timezone": "&4_&1.timezone",
"@5,name": "&4_&1.name",
"@3,channelId": "&4_&1.channelId",
"*": "&4_&1.&"
}
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": "[]"
}
}
]