Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aeldar/df4ec4535b549a3d09d81cbbd57c6b81 to your computer and use it in GitHub Desktop.

Select an option

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.
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'
@aeldar

aeldar commented Aug 15, 2019

Copy link
Copy Markdown
Author

E.g., the following ENV:

WEB_APP_STR="hello world"
WEB_APP_BOOL1="true"
WEB_APP_BOOL2="False"
WEB_APP_NUM="12345"
WEB_APP_NULL="null"

should return JSON:

{
  "STR": "hello world",
  "BOOL1": true,
  "BOOL2": false,
  "NUM": 12345,
  "NULL": null
}

@aeldar

aeldar commented Aug 15, 2019

Copy link
Copy Markdown
Author

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