Created
March 7, 2023 12:53
-
-
Save guillermodlpa/436e49ee254139c8b6a2a2cbcb384a75 to your computer and use it in GitHub Desktop.
Snippet of code to format a plain JSON encoded object into env var file format (KEY=value) using jq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Formats something like | |
| # | |
| # '{"MODE":"dev","HOST":"db"}' | |
| # | |
| # to | |
| # | |
| # MODE=dev | |
| # HOST=db | |
| # | |
| # Using printf and the quotes around the variable are important to preserve spaces and \n chars in the values | |
| printf '%s\n' "$JSON" | jq -j "to_entries|map(\"\(.key)=\(.value|tostring)\n\")|.[]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment