I need to parse the jsonarray by using regex. My json is
"keys": [
{
"host": "example.com"
},
{
"host": "example.net"
}
]
I need to get the two hosts values.
With this information, it is possible to use regex to filter a JSON object to return the key, the value, and the parent object chain.
When you want to extract text, grep
is your friend:
grep -Po '(?<="host": ")[^"]*' myjsonFile
For example:
kent$ echo '"keys": [
{
"host": "example.com"
},
{
"host": "example.net"
}
]'|grep -Po '(?<="host": ")[^"]*'
example.com
example.net
The following regex will grab your host values using a non-greedy kleene wildcard:
/"host":\s"(.*?)"/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With