staticx
staticx

Reputation: 1281

Parsing a JSON results from influxdb HTTP requests

I am querying InfluxDB using curl requests and I got a result that looks like:

{
    "results": [
        {
            "series": [
                {
                    "name": "memory_usage",
                    "columns": [
                        "time",
                        "max"
                    ],
                    "values": [
                        [
                            "2017-07-24T10:43:37.844581595Z",
                            872898560
                        ]
                    ]
                }
            ]
        }
    ]
}

I want to extract automatically the last value (in this example it is 872898560).

Upvotes: 0

Views: 798

Answers (1)

jq170727
jq170727

Reputation: 14625

Here is a solution using jq. If data.json contains the sample data then the command

$ jq -M '.results[].series[].values[][-1]' data.json

produces

872898560

Upvotes: 1

Related Questions