如何转换JSON数组?

问题描述 投票:0回答:1

我需要转换这个json数组:

[
    {
        "timestamp": "2025-01-19T17:00:00Z",
        "absoluteDeviationsX": [10, 11, 12 ]
    },
    {
        "timestamp": "2025-01-20T17:00:00Z",
        "absoluteDeviationsX": [20, 21, 22 ]
        ]
    }
]

至:

[
    {
    "timestamp": "2025-01-19T17:00:00Z",
    "absoluteDeviationsX0": 10,
    "absoluteDeviationsX1": 11,
    "absoluteDeviationsX2": 12,
    },
    {
    "timestamp": "2025-01-20T17:00:00Z",
    "absoluteDeviationsX0": 20,
    "absoluteDeviationsX1": 21,
    "absoluteDeviationsX2": 22,
    }
]

使用 JSONata。

我需要这个来处理 Grafana 的 Infinity 插件中的数据。

jsonata
1个回答
-1
投票
$.$merge([
    { "timestamp": timestamp },
    absoluteDeviationsX#$i{
        "absoluteDeviationsX" & $i: $
    }
])

参见 https://try.jsonata.org/EtmrHNM7U

© www.soinside.com 2019 - 2024. All rights reserved.