Runs a program in a modified environment, specified via JSON.
Go Perl 6 Perl Shell Makefile
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Run a program in a modified environment, specified via JSON.


usage: ./envjson [OPTIONS]... JSONfile [COMMAND [ARG]...]

Ensure that the environment meets JSONfile requirements and run COMMAND.

  -d, --display-docs  displays documentation for variables in spec
  -h, --help     display this help and exit
  -i, --ignore-environment  start with an empty environment
  -,  --stdin    insert read JSON key-value pairs into environment
  -v, --validate-json  validates envjson file

If no COMMAND, print the resulting environment as JSON.

By default, envjson reads the local environment and merges it with the JSON file required on the command line. We refer to the provided JSON file as the "spec". If the spec's requirements are met, e.g., all required variables are present, it launches the command with an environment made up of the initial local environment, with defaults added in from the spec. Therefore, the command:

envjson requirements.json /usr/local/bin/some-12-factor-app

ensures that /usr/local/bin/some-12-factor-app won't be launched unless all variables marked "required" in requirements.json are non-empty.

Specifying requirements.json

The so called environment "spec" is a single JSON object, with the following structure:

  "ENVIRONMENT_VARIABLE": "default value",
    "required": true,
    "inherit": false,
    "value": "<string>",
    "doc": "<string>"

The meaning of each key is as follows:

  • required: The command cannot be run if this variable has no value.
  • inherit: The variable doesn't have a value, and must be inherited from the environment.
  • value: The value that should be used for this variable.
  • doc: Documentation about the meaning of this environment variable. This has no effect on it's value.


Contributions are welcome, and encouraged! Please open an issue before a Pull Request to avoid duplicated effort, and/or functionality that will not be merged.



(c) 2016, Andrew Gwozdziewycz

See LICENSE file for more information.