Last active
September 6, 2019 19:43
-
-
Save aeldar/df4ec4535b549a3d09d81cbbd57c6b81 to your computer and use it in GitHub Desktop.
Convert ENV to JSON, filtered by prefix "WEB_APP_", with prefix removed, and with Boolean and Number values recognized. `jq` was used.
This file contains 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
jq -n \ | |
'env | |
| to_entries | |
| map(select(.key | startswith("WEB_APP_"))) | |
| map({ | |
"key": (.key | sub("WEB_APP_"; "")), | |
"value": ( | |
if (.value | test("^true$"; "i")) then true | |
elif (.value | test("^false$"; "i")) then false | |
elif (.value | test("[[:digit:]]+")) then (.value | tonumber) | |
elif (.value | test("^null$"; "i")) then null | |
else .value end)}) | |
| from_entries' |
Objects are not parsed, because DON'T PLACE OBJECTS INTO ENV!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
E.g., the following ENV:
should return JSON: