我有一个 JSON 输入,我使用 JOLT 符号将其转换为另一个 JSON。我有需要保存为键值对的测量值,车站名称和车站编号合并为一个字段,日期字段需要单独保存。除了获取时间并将其转换为 GMT 之外,我已经生成了相应的输出。请查看我的输入 JSON 和预期输出 JSON 并修改我当前的 JOLT。
输入 JSON:
[
{
"station_id": 1919,
"local_time_last_update": "2024-11-05 10:45:21",
"ts": 1730796321,
"temperature": 19.7,
"humidity": 49,
"pressure": 1026.87,
"wind_average": 1.6,
"wind_direction": 270,
"total_rain": 0,
"solar_radiation": 0,
"FDI": 38,
"fault_status": 0,
"station_Name": "Silicon Valley "
}
]
预期产出:
{
"data": [
{
"code": "temperature",
"value": 19.7
},
{
"code": "humidity",
"value": 49
},
{
"code": "pressure",
"value": 1026.87
},
{
"code": "wind_average",
"value": 1.6
},
{
"code": "wind_direction",
"value": 270
},
{
"code": "total_rain",
"value": 0
},
{
"code": "solar_radiation",
"value": 0
},
{
"code": "FDI",
"value": 38
},
{
"code": "fault_status",
"value": 0
}
],
"stationname": "1919_Silicon Valley",
"Date": "2024-11-05 08:45:21"
}
- 所有度量都保存为键值对
- 车站名称 = 车站名称 + 车站 ID
- Date” = local_time_last_update 转换为 GMT(ts 字段也可以转换为 GMT)
当前 JOLT 规格:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"timestamp": "${ts:multiply(1000):format('yyyy-MM-dd HH:mm:ss', 'Etc/GMT-1')}"
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"local_time_last_update": "",
"ts": "",
"station_id": ""
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"timestamp": "Date",
"*": {
"$": "data[#2].code",
"@": "data[#2].value"
},
"station_Name": "stationname"
}
}
}
]