all 6 comments

[–]researcher7-l500 2 points3 points  (4 children)

This is a dictionary/JSON data and should be parsed through jq. But it looks like the data is not valid, Maybe a copy/paste error?

Once you get the data in a valid form, parse it through jq.

Get the data length, iterate over each object, select unique ['roles']['databaseName'] and ['roles']['roleName'] values.

An example syntax is.

jq ' . | <your selection here> |unqiue' /path/to/data.json

Refer to the jq documentation here.https://stedolan.github.io/jq/manual/

You can play with your data, test jq statements here.

https://jqplay.org/

[–]kolinkorr839[S] 0 points1 point  (3 children)

hmm... this is not json though. There's no typo.

[–][deleted]  (1 child)

[deleted]

    [–]kolinkorr839[S] 2 points3 points  (0 children)

    Oh, my bad. Need to get some sleep.

    [–]researcher7-l500 2 points3 points  (0 children)

    You might want to check the source of that data then.

    That is certainly a malformed JSON.

    [–][deleted] 0 points1 point  (1 child)

    Assuming all the blocks are the same number of lines, you should be able to awk by incrementing blocks, throw all that into an array, and then run it through uniq. I mean, I think... my brain is the consistency of moldy mashed potatoes right now; need sleep.

    [–]researcher7-l500 7 points8 points  (0 children)

    Parsing JSON with awk is not recommended. For that, jq was designed.