W
W
winmasta2017-09-02 12:23:44
JSON
winmasta, 2017-09-02 12:23:44

How can one select the same key from different JSON keys?

JSON available

{
  "key_abc123": {
    "a": "1",
    "b": "sj",
    "ip": "4.15.0.1"
  },
  "key_defg4567": {
    "a": "1",
    "b": "sj",
    "ip": "4.15.0.6"
  },
  "key_hi89": {
    "a": "1",
    "b": "sj",
    "ip": "4.15.0.4"
  }
}

How can bash iterate over all keys and get ip in a loop?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
winmasta, 2017-09-03
@winmasta

I came up with such a crutch on the head:

echo $JSON | jq --raw-output '.[].ip' > array
while read IP
do
     тут действие для каждого ip адреса
done < array

D
Dimonchik, 2017-09-02
@dimonchik2013

field hockey is not very good, choose Python and things will move

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question