mold
A blazing fast CLI tool that generates TypeScript types, Zod schemas, and Prisma models from JSON.
Installation
Usage
# Generate TypeScript interfaces
# Generate Zod schema
# Generate Prisma model
# Generate all formats
# Output to files instead of stdout
# Custom type name (default: inferred from filename)
# Flat mode - keep nested objects inline
Example
Input (user.json):
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