miércoles, 25 de agosto de 2021

A couple of jq tricks

 There's 2 jq functions I'm using a lot, and I don't see many people using: "join" and "fromjson".

The first one, is join, which joins arrays into a single string. I shared it in a HN thread about jq. That thread has some nice tricks, check it out if you do that kind of json parsing in the CLI.

The other one is "fromjson", and you use it like this:  

     echo '"{\"a\":1}"' | jq fromjson.a      # 1


A concrete practical example is in when fetching secrets from aws secretsmanager. A secret's content is a string, that is really a json.

     aws secretsmanager get-secret-value --secret-id  <secret-key> | jq '.SecretString| fromjson.key_of_the_json' -r