Env JSON parser
Library that parses JSON structures out of environment variables
Installation
npm install --save env-json-parser
Usage
Paths are constructed as follows:
.
separates nested objects
:
separates arrays
Values always need to be JSON encoded
Example
Environment
DEMO_KEY1="test"DEMO_KEY2.SUBKEY.NESTEDSUBKEY=42DEMO_KEY3:0=trueDEMO_KEY4={"subkey":"test"}
Typescript
// import the library; // create an instance of the parser with the prefix as parameter, names are case insensitive; // get the complete structure as objectenvJsonParser.get;/*{ key1: "test", key2: { subkey: { nestedsubkey: 42 } }, key3: [ true ], key4: { subkey: "test" }}*/ // get a part of the structureenvJsonParser.get'key2.subkey';/* { nestedsubkey: 42 }*/