使用jq从json获取数组

我有一个以下json

    {
    "status": "success","data": {
            "resultType": "matrix","result": [{
                    "metric": {},"values": [[1573452693.024,"36380.58030773418"],[1573452707.024,"51397.82785694454"],[1573452721.024,"38711.55804872829"],[1573452735.024,"47801.74418514242"],[1573452749.024,"42140.81258908656"]]
                    }]
            }
    }

我使用jq通过以下方式提取values

    curl "LINK" | .\\jq.exe -c '.data.result[].values'

但是返回字符串,我需要遍历接收到的数组。我需要使用这些值:1.获取对; 2.将Unix TimeStamp更改为可读的; 3.保存为CSV。如何提取数组作为输出?

在Thor答案中使用扩展的json编辑评论:

{
    "status": "success","data": {
        "resultType": "matrix","result": [{
            "metric": {"container_name":"name1"},[15734 52749.024,"42140.81258908656"]]
        },{
            "metric": {"container_name":"name2"},{
            "metric": {"container_name":"name3"},"42140.81258908656"]]
        }
        ]
    }
}
happylady0001a 回答:使用jq从json获取数组

您可以在jq中完成所有操作,例如:

jq -r '.data.result[].values | .[] | .[0] |= strftime("%Y-%m-%d %H:%M") | @csv'

输出:

"2019-11-11 06:11","36380.58030773418"
"2019-11-11 06:11","51397.82785694454"
"2019-11-11 06:12","38711.55804872829"
"2019-11-11 06:12","47801.74418514242"
"2019-11-11 06:12","42140.81258908656"
本文链接:https://www.f2er.com/3124934.html

大家都在问