Skip to content

impsislegobatman/json2types

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json2types

Convert JSON to TypeScript type definitions. Pipe it, pass a file, or grab from clipboard.

Install

npm install -g json2types

Or use directly with npx:

npx json2types input.json

Usage

# From a file
json2types data.json

# From stdin
echo '{"name": "Alice", "age": 30}' | json2types

# From clipboard
json2types --clipboard

# Custom root type name
json2types data.json --name User

Example

Input:

{
  "id": 1,
  "name": "Alice",
  "email": null,
  "address": {
    "street": "123 Main St",
    "city": "Springfield"
  },
  "tags": ["admin", "user"]
}

Output:

interface Address {
  street: string;
  city: string;
}

interface Root {
  id: number;
  name: string;
  email?: unknown;
  address: Address;
  tags: string[];
}

CLI Flags

Flag Description
--name <name>, -n Name for the root type (default: Root)
--clipboard, -c Read JSON from system clipboard
--help, -h Show help
--version, -v Show version

Features

  • Nested object detection with named interfaces
  • Array element type inference
  • Null values become optional properties
  • Mixed-type arrays become union types
  • Keys with special characters are quoted
  • Zero runtime dependencies

License

MIT

About

Convert JSON to TypeScript interfaces. CLI + web. Zero config.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors