I have the following command to grab a json in unix:
wget -q -O- https://www.reddit.com/r/NetflixBestOf/.json
Which gives me the following output format (with different results each time obviously):
{
"kind": "...",
"data": {
"modhash": "",
"whitelist_status": "...",
"children": [
e1,
e2,
e3,
...
],
"after": "...",
"before": "..."
}
}
where each element of the array children is an object structured as follows:
{
"kind": "...",
"data": {
...
}
}
Here is an example of a complete .json get (body is too long to post directly: https://pastebin.com/20p4kk3u
I need to print the complete data object as present inside each element of the array children. I know I need pipe atleast twice, to initially get children [...], then data {...} from there on, and this is what I have so far:
wget -q -O- https://www.reddit.com/r/NetflixBestOf/.json | tr -d '\r\n' | grep -oP '"children"\s*:\s*\[\s*\K({.+?})(?=\s*\])' | grep -oP '"data"\s*:\s*\K({.+?})(?=\s*},)'
I'm new to regular expressions, so I'm not sure how to handle having brackets or curly braces within elements of what I'm grepping. The line above prints nothing to the shell and I'm not sure why. Any help is appreciated.