Skip to content

About

Zero-dependency CLI & library to generate strongly-typed models (TypeScript, Pydantic, Zod, Go, Rust, SQL) from JSON and LLM structured outputs.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ json-polyglot

CI License: MIT Zero Dependencies Web Suite

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.


🌟 Why json-polyglot?

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.


πŸ“¦ Installation & Quickstart

Run instantly with npx (No install needed):

npx json-polyglot data.json --target pydantic --name User

Install globally:

npm install -g json-polyglot

Install as a project dependency:

npm install json-polyglot

πŸ’» CLI Usage

Basic File Input

# 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

Piping from Stdin & LLM CLI Tools

# 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

CLI Options:

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

πŸ› οΈ Programmatic Node.js API

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');

πŸ“‹ Generated Output Examples

Python (Pydantic v2)

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: Profile

TypeScript

export interface Profile {
  avatarUrl: string;
  bio: string;
}

export interface User {
  id: number;
  username: string;
  isActive: boolean;
  roles: string[];
  profile: Profile;
}

Zod Validation Schema

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>;

πŸ§ͺ Testing

Run the automated test suite verifying all 7 language generators:

npm test

🌐 Community & Ecosystem

json-polyglot powers the client-side code generation engines at aijsongenerator.com, an open suite of 100+ free developer tools.

πŸ“„ License

MIT Β© CloudConsultant2

About

Zero-dependency CLI & library to generate strongly-typed models (TypeScript, Pydantic, Zod, Go, Rust, SQL) from JSON and LLM structured outputs.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages