mold-cli

Crates.iomold-cli
lib.rsmold-cli
version0.2.0
created_at2025-12-06 14:26:27.382776+00
updated_at2025-12-06 15:03:22.104992+00
descriptionJSON to TypeScript/Zod/Prisma generator CLI
homepagehttps://github.com/pumarogie/mold
repositoryhttps://github.com/pumarogie/mold
max_upload_size
id1970280
size75,210
Phillips Uwumarogie (pumarogie)

documentation

README

mold

A blazing fast CLI tool that generates TypeScript types, Zod schemas, and Prisma models from JSON.

Installation

cargo install mold-cli

Usage

# Generate TypeScript interfaces
mold schema.json --ts

# Generate Zod schema
mold schema.json --zod

# Generate Prisma model
mold schema.json --prisma

# Generate all formats
mold schema.json --all

# Output to files instead of stdout
mold schema.json --all -o ./generated

# Custom type name (default: inferred from filename)
mold data.json --ts --name User

# Flat mode - keep nested objects inline
mold schema.json --ts --flat

Example

Input (user.json):

{
  "id": 1,
  "name": "John Doe",
  "email": "john@example.com",
  "active": true,
  "profile": {
    "bio": "Developer",
    "avatar": "https://example.com/avatar.png"
  }
}

Output (--ts):

interface UserProfile {
  avatar: string;
  bio: string;
}

interface User {
  active: boolean;
  email: string;
  id: number;
  name: string;
  profile: UserProfile;
}

Output (--zod):

import { z } from "zod";

const UserProfileSchema = z.object({
  avatar: z.string(),
  bio: z.string(),
});

const UserSchema = z.object({
  active: z.boolean(),
  email: z.string(),
  id: z.number().int(),
  name: z.string(),
  profile: UserProfileSchema,
});

type UserProfile = z.infer<typeof UserProfileSchema>;
type User = z.infer<typeof UserSchema>;

export { UserProfileSchema, UserSchema };
export type { UserProfile, User };

Output (--prisma):

model UserProfile {
  id     Int    @id @default(autoincrement())
  avatar String
  bio    String
}

model User {
  id     Int     @id @default(autoincrement())
  active Boolean
  email  String
  name   String
}

Features

  • Type inference - Automatically detects string, number, integer, boolean, null, arrays, and objects
  • Nested type extraction - Nested objects are extracted as separate types/schemas
  • Union types - Mixed arrays like [1, "two", true] become union types
  • Flat mode - Keep nested objects inline with --flat
  • Multiple outputs - Generate all formats at once with --all

CLI Options

Usage: mold [OPTIONS] <FILE>

Arguments:
  <FILE>  Path to JSON file

Options:
  -t, --ts            Generate TypeScript interfaces
  -z, --zod           Generate Zod schema
  -p, --prisma        Generate Prisma model
  -a, --all           Generate all formats
  -o, --output <DIR>  Output directory (default: stdout)
  -n, --name <NAME>   Root type name (default: inferred from filename)
      --flat          Keep nested objects inline (no extraction)
  -h, --help          Print help
  -V, --version       Print version

License

MIT

Commit count: 0

cargo fmt