env-json-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Env JSON parser

Library that parses JSON structures out of environment variables

NPM Version Package License NPM Downloads CI

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=42
DEMO_KEY3:0=true
DEMO_KEY4={"subkey":"test"}

Typescript

// import the library
import {EnvJsonParser} from 'env-json-parser';
 
// create an instance of the parser with the prefix as parameter, names are case insensitive
const envJsonParser = new EnvJsonParser('DEMO_');
 
// get the complete structure as object
envJsonParser.get();
/*
{
    key1: "test",
    key2: {
        subkey: {
            nestedsubkey: 42
        }
    },
    key3: [
        true
    ],
    key4: {
        subkey: "test"
    }
}
*/
 
// get a part of the structure
envJsonParser.get('key2.subkey');
/*
    {
        nestedsubkey: 42
    }
*/

Package Sidebar

Install

npm i env-json-parser

Weekly Downloads

14

Version

1.0.2

License

MIT

Unpacked Size

9.48 kB

Total Files

9

Last publish

Collaborators

  • koenig-dominik