https://github.com/koenig-dominik/env-json-parser
Library that parses JSON structures out of environment variables
https://github.com/koenig-dominik/env-json-parser
12factor env environment json node object parser ts typescript
Last synced: about 2 months ago
JSON representation
Library that parses JSON structures out of environment variables
- Host: GitHub
- URL: https://github.com/koenig-dominik/env-json-parser
- Owner: koenig-dominik
- License: mit
- Created: 2020-05-08T02:20:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T17:57:32.000Z (over 3 years ago)
- Last Synced: 2025-10-14T13:17:06.413Z (8 months ago)
- Topics: 12factor, env, environment, json, node, object, parser, ts, typescript
- Language: TypeScript
- Homepage:
- Size: 2.04 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Env JSON parser
Library that parses JSON structures out of environment variables
## Installation
```shell script
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
```dotenv
DEMO_KEY1="test"
DEMO_KEY2.SUBKEY.NESTEDSUBKEY=42
DEMO_KEY3:0=true
DEMO_KEY4={"subkey":"test"}
```
Typescript
```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
}
*/
```