I have an online JSON file. Every time I try to download it. But I need to parse this JSON and get online ip's between double-quotes. Normally I can parse it with jq like .sample[].echo etc. but my list bigger than that example1,2..300 store more than 300 block data in it. I need to parse and get only inside of double quotes and get the all ip's.
By the way: I saw many questions on stackover but none of them related to filtering this kind of input
curl -L "https://sample.data.com/ip.json" -o 'ip.json' | *need to parsing method here*
Here is my JSON file:
{
"sample1": {
"echo": [
"255.254.253.0/32"
],
"delta": [
"199.231.211.0/32"
]
},
"sample2": {
"beta": [
"250.123.124.0/32"
],
"pre": [
"122.156.243.0/32"
]
},
.
.
.
.
.
}
CodePudding user response:
If you want to extract all strings that looks like an IP, then you can still use jq
. If we "fix" your example JSON above, to be actual JSON, then running the following jq program:
.. | strings | match("\\d \\.\\d \\.\\d \\.\\d (?:/\\d )?").string
over it would output:
"255.254.253.0/32"
"199.231.211.0/32"
"250.123.124.0/32"
"122.156.243.0/32"
I guess your don't want to keep the IPs quored, this can be handled with -r
output flag
$ curl ... | jq -r '.. | strings | match("\\d \\.\\d \\.\\d \\.\\d (?:/\\d )?").string'
255.254.253.0/32
199.231.211.0/32
250.123.124.0/32
122.156.243.0/32