Zero-dependency CLI & universal library to generate strongly-typed models (TypeScript, Python Pydantic v2, Zod, Go, Rust Serde, SQL) from raw JSON and LLM structured outputs.
When building AI agents, microservices, or public APIs, translating raw JSON payloads into strongly-typed models across multiple programming languages is painful. Existing generators often require heavyweight runtimes, python environments, or send your proprietary payloads to remote servers.
json-polyglot provides:
- β‘ Zero Dependencies: Pure, native V8 execution with zero runtime bloat.
- π 100% Offline & Private: Zero data collection, telemetry, or remote server calls. Safe for proprietary schemas.
- π€ LLM Structured Output Ready: Seamlessly pipe outputs from OpenAI, Anthropic, or local models into production-ready types.
- π Polyglot: One unified tool generates TypeScript, Python (Pydantic v2 & dataclasses), Zod, Go, Rust, and SQL DDL.
- π» Dual Mode: Use as an instant terminal CLI (
npx json-polyglot) or programmatic Node.js library.
Prefer an interactive visual web interface? Use the free online version at aijsongenerator.com.
npx json-polyglot data.json --target pydantic --name Usernpm install -g json-polyglotnpm install json-polyglot# Generate Python Pydantic v2 Models
json-polyglot payload.json -t pydantic -n CustomerOrder
# Generate TypeScript Interfaces
json-polyglot payload.json -t typescript -n ApiResponse
# Generate Zod Validation Schemas
json-polyglot payload.json -t zod -n UserProfile
# Generate Go Structs with json tags
json-polyglot payload.json -t go -n EventRecord
# Generate Rust Structs with Serde attributes
json-polyglot payload.json -t rust -n ConfigPayload
# Generate SQL Table DDL
json-polyglot payload.json -t sql -n users# Pipe from curl API response
curl -s https://api.github.com/users/octocat | json-polyglot -t pydantic -n GithubUser
# Pipe from cat or LLM outputs
cat model_output.json | json-polyglot -t zod -o schema.ts| Flag | Description | Default |
|---|---|---|
-t, --target <lang> |
Target language (typescript, pydantic, dataclass, zod, go, rust, sql) |
typescript |
-n, --name <name> |
Root model or table name | RootModel |
-o, --output <file> |
Write output to a file instead of stdout | stdout |
-v, --version |
Output version | |
-h, --help |
Display help screen |
const {
generate,
generatePython,
generateTypeScript,
generateZod,
generateGo,
generateRust,
generateSqlSchema
} = require('json-polyglot');
const sample = {
id: 42,
username: "alex_dev",
isActive: true,
roles: ["admin", "developer"],
profile: {
avatarUrl: "https://example.com/avatar.png",
bio: "Systems architect"
}
};
// 1. Universal generate() dispatcher
const pydanticCode = generate(sample, { target: 'pydantic', rootName: 'User' });
console.log(pydanticCode);
// 2. Direct language methods
const tsCode = generateTypeScript(sample, 'User');
const zodCode = generateZod(sample, 'User');
const goCode = generateGo(sample, 'User');
const rustCode = generateRust(sample, 'User');
const sqlCode = generateSqlSchema(sample, 'users');from typing import List, Optional, Any
from pydantic import BaseModel, Field
class Profile(BaseModel):
avatar_url: str
bio: str
class User(BaseModel):
id: int
username: str
is_active: bool
roles: List[str]
profile: Profileexport interface Profile {
avatarUrl: string;
bio: string;
}
export interface User {
id: number;
username: string;
isActive: boolean;
roles: string[];
profile: Profile;
}import { z } from "zod";
export const profileSchema = z.object({
avatarUrl: z.string(),
bio: z.string(),
});
export type Profile = z.infer<typeof profileSchema>;
export const userSchema = z.object({
id: z.number().int(),
username: z.string(),
isActive: z.boolean(),
roles: z.array(z.string()),
profile: profileSchema,
});
export type User = z.infer<typeof userSchema>;Run the automated test suite verifying all 7 language generators:
npm testjson-polyglot powers the client-side code generation engines at aijsongenerator.com, an open suite of 100+ free developer tools.
MIT Β© CloudConsultant2