npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

ajsc

v2.0.0

Published

Another Json-Schema Converter

Readme

ajsc - Another JSON Schema Parser

ajsc is an npm package that transforms JSON Schema definitions into an intermediate representation (IR) called IRNode. This intermediate form is designed to be consumed by language-specific converters—such as the built-in TypeScript converter—or by any custom converter you create for languages like Kotlin or Swift. This library streamlines the process of converting API JSON Schema definitions into strong-typed code representations, ensuring consistency between your API contracts and client implementations.


Features

  • Comprehensive Schema Parsing:
    Convert JSON Schema types including strings, numbers, booleans, nulls, literals, enums, unions, intersections, arrays, and objects into a unified IR.

  • Intermediate Representation (IRNode):
    The IRNode provides a standard structure that captures type, constraints, and path information. This representation is ideal for further transformation into various target languages.

  • Plugin-Based Architecture:
    Use the provided language plugin (currently, a TypeScript converter) or write your own converter to support additional languages such as Kotlin or Swift.

  • $defs and References Handling:
    Resolve JSON Schema definitions ($defs) and references ($ref) seamlessly, ensuring reusable schema components are properly processed.

  • Unique Signature Tracking:
    For objects and arrays, the library tracks unique signatures to avoid duplicate type definitions when converting to code.


Installation

Install ajsc via npm:

npm install ajsc

Usage

Basic Conversion to IRNode

The primary function of ajsc is to convert a JSON Schema into an IRNode. Here’s an example of converting a simple JSON Schema that defines a string type:

import { JSONSchemaConverter } from "ajsc";

const schema = { type: "string" };
const converter = new JSONSchemaConverter(schema);

console.log(converter.irNode);
// Output:
// {
//   type: "string",
//   constraints: {},
//   path: "",
// }

Converting Complex Schemas You can also convert more complex schemas including objects, arrays, unions, intersections, and even schemas with $defs:

import { JSONSchemaConverter } from "ajsc";

const complexSchema = {
  $defs: {
    Person: {
      type: "object",
      properties: {
        name: { type: "string" },
        age: { type: "number" },
      },
      required: ["name"],
    },
  },
  type: "object",
  properties: {
    person: { $ref: "#/$defs/Person" },
  },
};

const converter = new JSONSchemaConverter(complexSchema);
console.log(converter.irNode);

API Reference

JSONSchemaConverter

  • Constructor: new JSONSchemaConverter(schema: object)
  • Properties:
    • irNode: The resulting intermediate representation of the JSON Schema.
  • Supported Schema Types:
    • Primitive Types: string, number, boolean, null
    • Literals: Using the const keyword.
    • Enums: Using the enum property.
    • Unions: When type is an array (e.g., ["string", "number"]).
    • Intersections: Using allOf to combine multiple schemas.
    • Arrays: With type: "array" and an items schema.
    • Objects: With type: "object" and a properties definition.
    • $defs and $ref: For defining and referencing reusable schema parts.

TypescriptConverter

The package includes a TypeScript language plugin that converts the IRNode into TypeScript type definitions.

  • Constructor: new TypescriptConverter(schema: object, options?: { inlineTypes?: boolean })
  • Properties:
    • code: A string containing the generated TypeScript code.

Usage Example:

import { TypescriptConverter } from "ajsc";

const schema = {
  type: "object",
  properties: {
    name: { type: "string" },
    age: { type: "number" },
    contacts: {
      type: "array",
      items: {
        type: "object",
        properties: {
          email: { type: "string" },
        },
        required: ["email"],
      },
    },
    profile: {
      type: "object",
      properties: {
        email: { type: "string" },
      },
      required: ["email"],
    },
  },
  required: ["name", "age"],
};

const tsConverter = new TypescriptConverter(schema, { inlineTypes: true });
console.log(tsConverter.code);

// Expected output (formatted):
// {
//   name: string;
//   age: number;
//   contacts?: Array<{ email: string; }>;
//   profile?: { email: string; };
// }