{"id":23745251,"url":"https://github.com/antelman107/json-env-go","last_synced_at":"2026-05-18T04:03:55.815Z","repository":{"id":57530944,"uuid":"276373936","full_name":"antelman107/json-env-go","owner":"antelman107","description":"GO package to deal with complex configs provided through environment variables.","archived":false,"fork":false,"pushed_at":"2020-07-01T13:19:13.000Z","size":6,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-31T12:56:42.109Z","etag":null,"topics":["configuration","environment-variables","golang","json","viper"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antelman107.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-01T12:38:25.000Z","updated_at":"2021-07-12T21:08:27.000Z","dependencies_parsed_at":"2022-09-05T09:51:19.131Z","dependency_job_id":null,"html_url":"https://github.com/antelman107/json-env-go","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antelman107%2Fjson-env-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antelman107%2Fjson-env-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antelman107%2Fjson-env-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antelman107%2Fjson-env-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antelman107","download_url":"https://codeload.github.com/antelman107/json-env-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239898456,"owners_count":19715212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["configuration","environment-variables","golang","json","viper"],"created_at":"2024-12-31T12:56:54.199Z","updated_at":"2025-10-11T07:32:07.764Z","avatar_url":"https://github.com/antelman107.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# What is it?\nTiny (1 line) GO package to deal with complex configs provided through environment variables.\n\n# Why we need it?\nIn dockerized applications and by https://12factor.net/ recommendation\nwe have to pass configuration for our GO program through environment variables.\n\nIt is easy if configuration consists of simple values (strings, numbers, boolean, etc), something like this:\n\n```json\n{\n      \"login\":\"user\",\n      \"password\":\"somepass\",\n      \"mfa_enabled\": true\n}\n```\n\nIn this case we could use several environment variables like  `APP_LOGIN=\"user\" APP_PASSWORD=\"somepass\"`.\n\nBut how would we work with complex configuration that, for example, consists of arrays of objects? For example:\n```json\n{\n      \"nodes\":[\n            {\n                  \"url\":\"http://1.localhost/\",\n                  \"priority\":1,\n                  \"enabled\":true\n            },\n            {\n                  \"url\":\"http://2.localhost/\",\n                  \"priority\":2,\n                  \"enabled\":false\n            }\n      ]\n}\n```\n\nThis package is aimed to deal with such configs.\nJust put the config into single environment variable.\nIt could be multiline, but work with single line is simplier from `bash`.\n\nRunning program `bash` example:\n\n```bash\n\nCONFIG='{\"nodes\":[{\"url\":\"http:\\/\\/1.localhost\\/\",\"priority\":1,\"enabled\":true},{\"url\":\"http:\\/\\/2.localhost\\/\",\"priority\":2,\"enabled\":false}]}' ./app\n```\n\nGO program code example:\n```GO\nimport jsonEnvGo \"github.com/antelman107/json-env-go\"\n\ntype Config struct {\n\tNodes []struct {\n\t\tURL      string `json:\"url\"`\n\t\tPriority int    `json:\"priority\"`\n\t\tEnabled  bool   `json:\"enabled\"`\n\t} `json:\"nodes\"`\n}\n\nfunc main() {\n      var cfg Config\n      if err := jsonEnvGo.DecodeConfigFromEnv(\"CONFIG\", \u0026cfg); err != nil {\n            logger.Error(err)\n            return\n      }\n      \n      // cfg now filled, do something with it\n      // ...\n}\n```\n\nThis package is very tiny, it can be used instead of viper (https://github.com/spf13/viper) when working especially with json configs coming from environment variables.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantelman107%2Fjson-env-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantelman107%2Fjson-env-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantelman107%2Fjson-env-go/lists"}