Skip to content

Instantly share code, notes, and snippets.

@andrewthauer
Created August 22, 2020 21:05
Show Gist options
  • Save andrewthauer/9c5178e4d7c3bfe9cee26180d7a1ce7d to your computer and use it in GitHub Desktop.
Save andrewthauer/9c5178e4d7c3bfe9cee26180d7a1ce7d to your computer and use it in GitHub Desktop.
jq-examples
#!/usr/bin/env bash
#
# Adapted as a fix for https://github.com/spotify/backstage/blob/master/docker/run.sh
#
# Call with
local key_map='{ "BACKEND_BASEURL": "backend_baseUrl" }'
config="$(jq --arg keyMap "$key_map" -n 'env |
def swap_key($k): $keyMap | fromjson | if has($k) then with_entries(select(.key == $k)) | .[] else $k end;
with_entries(select(.key | startswith("APP_CONFIG_")) | .key |= sub("APP_CONFIG_"; "")) |
to_entries |
reduce .[] as $item (
{}; setpath(swap_key($item.key) | split("_"); $item.value | try fromjson catch $item.value)
)')"
>&2 echo "Runtime app config: $config"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment