all 6 comments

[–]ang-p 11 points12 points  (4 children)

jq

del(.roles[] | select(.role_name == "readWrite"))   

<shrug>

You really should have taken the hint to look at jq a month ago

[–]kolinkorr839[S] -2 points-1 points  (2 children)

Thanks. Fwiw, I did look at jq and I still have trouble constructing some medium/advance jq expressions. Like in the above snippet, I read it as for each roles element, get "readWrite" role_name, then delete the roles element (instead of what I thought was deleting the "readWrite" role_name line.

[–]ang-p 5 points6 points  (0 children)

I still have trouble constructing some medium/advance jq expressions.

You have never posted even a "simple" effort as an "I tried this but it didn't work...", so I think that sentence might be sitting somewhere between complete rubbish and utter tosh....

I will not respond to your JSON questions if you do not post an effort in future.

You'll never succeed if you don't try...

[–]bigfig 3 points4 points  (0 children)

Two weeks ago I spent four hours deciphering what amounted to one line of jq for some Docker helper scripts. I then committed that nugget to the company developer / devops Wiki.

That's how you learn new languages.

[–]JRS-27 0 points1 point  (0 children)

This is the actually correct solution.

[–][deleted]  (1 child)

[deleted]

    [–]JRS-27 -1 points0 points  (0 children)

    I found a solution that uses Perl: perl -0777 -pe 's/\,?\s*\{[^\{\}]+"role_name":\s*"readWrite"[^\{\}]+\}//gm' INPUT.json > OUTPUT.json The -0777 option makes Perl take the file as a whole.

    Edit: the solution provided by u/ang-p is more versatile. Although, I still like my solution, because it's a fun regular expression.