TJS-AJV is a handy tool that uses TJS to generate json schema from typescript interface, and uses AJV to validate a config file against the json schema.

How to use TJS-AJV?

  • Define your Interface file which will be used to dynamically generate the json schema. For example, the sample-schema.json schema file is generated from the typescript Interface sample-interface.ts by tjs-ajv.
  • Define your config file, from example sample-config.yml. This file will be validated against the above json schema by tjs-ajv.
  • Install tjs-ajv npm install tjs-ajv.

Sample code:

import * as path from "path";
import { loadConfig, validateConfig } from "tjs-ajv";

const INTERFACE_FILE = path.join(__dirname, "./sample-interface.ts");
const CONFIG_FILE = path.join(__dirname, "./sample-config.yml");

console.log("Validating config file, please wait...");
const loadResult = loadConfig(CONFIG_FILE);

if (!loadResult.success) {
} else {
  const validateResult = validateConfig(
  if (!validateResult.success) {
  } else {
    console.log("The config file is valid!");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s