0

I am making a curl request and the response in the in form like this:

data: [
    {
      data: {
         transaction: [
            [timestamp1, value1],
            [timestamp2, value2],
            [timestamp3, value3],
            [timestamp4, value4],
         ]
      }
    }
 ]
}

What I am doing

curl $url | jq -r '.data[].data[].tansaction'

which is giving output [ [key1: value1],[key2: value2], [key3: value], [key4: value] ]

What I want to is to store the above result in an array so that I can iterate over it. Final goal is to get each pair key and value and perform some operation over it

How can I do it in shell script?

5
  • It would help if you posted valid JSON. Did you mean {key1: value1} instead of [key1: value1]? Commented Oct 21, 2022 at 13:48
  • 1
    @glennjackman I think a correct JSON would have been {"key1": "value1"}. Commented Oct 21, 2022 at 14:15
  • Indeed, what @sonali put in his question does not validate as json, so jq will not work here. Please post the result of the curl. Commented Oct 21, 2022 at 14:59
  • Hi, sorry. That was a wrong json. I have updated it. Its actually an array with two elements, with zero index being time and first index being c=value observed at that time. I hope it makes sense now Commented Oct 22, 2022 at 8:38
  • jq -r '.data[].data[].tansaction | <iterate over it here>'. Typically, you would jq ... @tsv | while IFS=$'\t' read .... Commented Oct 22, 2022 at 9:24

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.