JSONからTypeScriptに変換
JSONからTypeScriptのinterfaceやtypeを生成します。
01
出力形式
interfaceまたはtypeを選択できます。
02
exportの追加
必要に応じてexportキーワードを追加できます。
技術情報
仕組み:
JSONのオブジェクト、配列、値から型を推定します。出力はinterfaceまたはtypeから選べます。
例:
{"id": 1, "name": "Alice"} becomes interface Root { id: number; name: string; }
活用例:
- >出力形式
- >exportの追加
よくある質問
実行時の検証にも使えますか?
いいえ。生成するのはTypeScriptの型宣言です。外部データの実行時検証は別途実装してください。
サンプル1件で全フィールドが分かりますか?
いいえ。サンプルにないフィールドや別の応答でだけ現れる値は確認が必要です。
データはサーバーに送信されますか?
いいえ。処理はブラウザ内で行われます。
他の言語
参考資料
結果の正しさをどう確認するか
以下の自動テストでこのツールを検証します。テスト例の名称は原文のまま掲載しています。
- Verification method
- Check generated TypeScript nulls, arrays, primitive roots and declarations against fixed JSON fixtures.
- Comparison reference
- Explicit declaration/field-mapping assertions and generator integration.
- Verification scope
- These cases are not all claimed to invoke the target-language compiler.
Test source and cases (select a file to read it)
-
generator-reliability.test.js
- JSON to TypeScript: nullable fields, arrays and primitive roots match explicit type fixtures
テスト対象は記載した例と境界条件です。すべての入力に対する証明ではありません。往復変換や同じライブラリによる確認は独立した検証ではありません。