1.0.0 • Published 8 months ago
@hrashkan/json-to-ts v1.0.0
json-to-ts
Generate TypeScript interfaces, type aliases, or both from JSON input (local file or remote URL).
🚀 Features
- Mode selection: output
interface,type, orbothvia--modeflag - Flexible input: accepts local JSON file paths or remote URLs
- Output control: print to stdout or write to a file
- Zero dependencies at runtime: built on Node.js and Quicktype-core
💿 Installation
# Install globally via npm
npm install -g json-to-tsOr clone and link locally:
git clone https://github.com/your-username/json-to-ts.git
cd json-to-ts
npm install
npm run build
npm linkRequires Node.js v16 or newer.
⚙️ Usage
json-to-ts -i <path|url> [options]Options
| Flag | Description | Default | |
|---|---|---|---|
| `-i, --input \<path | url>` | JSON file path or URL to fetch (required) | — |
-o, --output <file> | Output filename for the generated TypeScript definitions | stdout | |
-m, --mode <mode> | Generation mode: interface | type | both | interface | |
-V, --version | Show version number | — | |
-h, --help | Display help information | — |
Examples
Generate interfaces from a local file:
json-to-ts -i sample.jsonGenerate types from a remote URL and write to a file:
json-to-ts -i https://jsonplaceholder.typicode.com/todos/1 \
-m type \
-o todo-types.tsGenerate both interfaces and type aliases in one run:
json-to-ts -i sample.json -m both -o definitions.ts🛠️ Contributing
Contributions are welcome! Feel free to open issues or submit pull requests.
- Fork the repo
- Create a feature branch (
git checkout -b feature/name) - Commit your changes (
git commit -m "feat: ...") - Push to the branch (
git push origin feature/name) - Open a pull request
📜 License
MIT © Ashkan_Hooshidar
1.0.0
8 months ago