Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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.
{}
jq -r '.keys[] | .host'
When you want to extract text, grep is your friend:
grep
grep -Po '(?<="host": ")[^"]*' myjsonFile
For example:
kent$ echo '"keys": [ { "host": "example.com" }, { "host": "example.net" } ]'|grep -Po '(?<="host": ")[^"]*' example.com example.net
Add a comment
The following regex will grab your host values using a non-greedy kleene wildcard:
/"host":\s"(.*?)"/
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
{}); you could usejq -r '.keys[] | .host'