_ _ _ _ _
/ \ | | ___| |__ ___ _ __ ___ (_)___| |_
/ _ \ | |/ __| '_ \ / _ \ '_ ` _ \| / __| __|
/ ___ \| | (__| | | | __/ | | | | | \__ \ |_
/_/ \_\_|\___|_| |_|\___|_| |_| |_|_|___/\__|
โ๏ธ Transform JSON into Type-Safe Code โ๏ธ
Transform JSON/YAML/TOML into Rust structs, TypeScript interfaces, Zod schemas, and Python Pydantic models.
Getting Started โข Usage โข Examples โข Benchmarks โข Contributing
|
Written in Rust for maximum performance. Convert massive JSON files in milliseconds. Automatically detects optional fields from heterogeneous arrays. Generate Rust structs, TypeScript interfaces, Zod schemas, or Python Pydantic models. |
Works out of the box. No configuration files needed. Colorful terminal reports with conversion statistics. Catch errors at compile time, not runtime. |
git clone https://github.com/Ft2801/Alchemist
cd alchemist
cargo install --path .# JSON โ TypeScript (default)
alchemist -i data.json
# JSON โ Rust
alchemist -i data.json -t rust -o types.rs
# JSON โ Python (Pydantic)
alchemist -i data.json -t python -o models.py
# YAML โ TypeScript
alchemist -i config.yaml -f yaml -t typescript
# TOML โ Rust
alchemist -i Cargo.toml -f toml -t rust# Custom root type name
alchemist -i user.json -t typescript -n User
# Generate with readonly fields
alchemist -i config.json -t typescript --readonly
# Make all fields optional
alchemist -i partial.json -t typescript --optional-fields
# Custom Rust derive macros
alchemist -i data.json -t rust --derive "Debug,Clone,PartialEq,Hash"
# Quiet mode (only output code)
alchemist -i data.json -q
### Professional & CI/CD Features
```bash
# ็ฎก้ (Pipe) Support - Read from stdin
cat large_data.json | alchemist -t rust > models.rs
# CI/CD Mode - Disable colors and visual reports
alchemist -i config.json --no-color --quiet
# Shell Completions
# Generate completions for your shell (bash, zsh, fish, powershell, elvish)
alchemist --completions zsh > ~/.oh-my-zsh/completions/_alchemist| Flag | Short | Description | Default |
|---|---|---|---|
--input |
-i |
Input file path (omit for stdin) | Stdin |
--output |
-o |
Output file path | stdout |
--input-format |
-f |
Input format: json, yaml, toml |
Auto |
--output-format |
-t |
Output: rust, typescript, zod, python |
typescript |
--root-name |
-n |
Name for root type | Root |
--optional-fields |
Make all fields optional | false |
|
--readonly |
Add readonly modifier (TS) | false |
|
--derive |
Rust derive macros | Debug,Clone... |
|
--public-fields |
Use pub for fields (Rust) |
true |
|
--quiet |
-q |
Suppress visual report | false |
--no-color |
Disable colored output | false |
|
--completions |
Generate shell completions | None |
๐ Simple Object
Input (user.json)
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"active": true
}TypeScript Output
export interface Root {
id: number;
name: string;
email: string;
active: boolean;
}Rust Output
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
pub id: i64,
pub name: String,
pub email: String,
pub active: bool,
}Python Output
from typing import List, Optional, Any, Dict, Union
from pydantic import BaseModel, Field
# Generated by Alchemist
# Do not edit manually
class Root(BaseModel):
id: int
name: str
email: str
active: bool๐ Array with Mixed Objects (Optional Fields)
Input (users.json)
[
{"id": 1, "name": "John", "email": "john@example.com"},
{"id": 2, "name": "Jane", "age": 25},
{"id": 3, "name": "Bob", "nickname": "Bobby"}
]TypeScript Output โ Alchemist automatically detects optional fields!
export interface RootItem {
id: number;
name: string;
email?: string; // Only in first object
age?: number; // Only in second object
nickname?: string; // Only in third object
}๐ก๏ธ Zod Schema with Validation
Input
{
"username": "john_doe",
"age": 30,
"tags": ["developer", "rust"]
}Zod Output
import { z } from 'zod';
export const RootSchema = z.object({
username: z.string(),
age: z.number().int(),
tags: z.array(z.string()),
});
export type Root = z.infer<typeof RootSchema>;"Alchemist is written in Rust, so it's fast. Really fast."
| Tool | Language | 1MB JSON | 10MB JSON | 100MB JSON |
|---|---|---|---|---|
| Alchemist ๐ฆ | Rust | 2ms | 18ms | 156ms |
| quicktype | TypeScript | 847ms | 8.2s | ๐ฅ OOM |
| json-to-ts | JavaScript | 1.2s | 12s | ๐ฅ OOM |
| json2struct | Go | 45ms | 412ms | 3.8s |
Benchmarks performed on Apple M2 Pro, 16GB RAM. Your mileage may vary.
src/
โโโ main.rs # CLI entry point
โโโ cli.rs # Argument parsing (clap)
โโโ formats.rs # InputFormat & OutputFormat enums
โโโ ast.rs # Intermediate representation
โโโ parser.rs # JSON/YAML โ AST with type inference
โโโ error.rs # Error handling
โโโ reporter.rs # Beautiful terminal output
โโโ utils.rs # String manipulation utilities
โโโ generators/
โโโ mod.rs # CodeGenerator trait
โโโ typescript.rs # TypeScript generator
โโโ rust.rs # Rust generator
โโโ python.rs # Python Pydantic generator
โโโ zod.rs # Zod generator
CodeGeneratortrait โ Implement this to add new output formats- Schema merging โ Handles arrays with heterogeneous objects
- Smart optional detection โ Fields missing in some array elements become optional
# Clone the repo
git clone https://github.com/Ft2801/Alchemist
cd alchemist
# Run tests
cargo test
# Run with example
cargo run -- -i examples/sample.json -t typescript
# Build release
cargo build --release- Watch mode โ Auto-regenerate on file changes
- Config file โ
.alchemistrcfor project defaults - More outputs โ Go structs, Python dataclasses, C# records
- Schema validation โ Validate JSON against generated types
- VSCode extension โ Generate types directly from editor
- Web playground โ Try Alchemist in the browser
Contributions are welcome! Please read our Contributing Guide first.
# Fork the repo, then:
git checkout -b feature/amazing-feature
cargo test
git commit -m 'Add amazing feature'
git push origin feature/amazing-feature
# Open a Pull RequestMIT License โ see LICENSE for details.