Skip to Content
Zod Config

JSON5 adapter

Load configuration from a JSON5 file.

Loads the configuration from a json5 file.

Install

This adapter needs the json5 peer dependency, if you don't have it already:

npm install json5

The JSON5 adapter is synchronous, so it also works with loadConfigSync.

Usage

config.json5
{
  // Server settings
  host: 'localhost', // Single quotes + unquoted key
  port: 3000, // Trailing comma
  allowedIPs: [
    '192.168.0.1',
    '10.0.0.1', // Local access
  ],
}
import {  } from 'zod';
import {  } from 'zod-config';
import {  } from 'zod-config/json5-adapter';
import path from 'path';

const  = path.(, 'config.json5');

const  = .({
  : .(),
  : .(),
  : .(.()),
});

const  = await ({
  : ,
  : ({ :  }),
});

Options

OptionTypeDescription
pathstringPath to the JSON5 file. Required.

Also accepts the shared adapter options: regex, silent, keyMatching and transform.

On this page