JSON adapter
Load configuration from a JSON file.
Loads the configuration from a json file.
Install
No extra dependency. The JSON adapter is synchronous, so it also works with loadConfigSync.
Usage
import { } from 'zod';
import { } from 'zod-config';
import { } from 'zod-config/json-adapter';
import path from 'path';
const = .({
: .().(/^\d+$/),
: .(),
});
const = path.(, 'config.json');
const = await ({
: ,
: ({ : }),
});
// using filter regex to match only the keys we need
const = await ({
: ,
: ({
: ,
: /^MY_APP_/,
}),
});Options
| Option | Type | Description |
|---|---|---|
path | string | Path to the JSON file. Required. |
Also accepts the shared adapter options: regex, silent, keyMatching and transform.