跳转到主要内容
CuteJSON
↑↓ 导航 Enter 选择 Esc 关闭

JSON to TypeScript

Turn a document you already have into TypeScript interfaces, Python dataclasses, Go structs or Rust structs you can paste into a project.

返回所有工具

键盘快捷键

这些快捷键在页面上对应操作存在时有效。

打开命令面板
Ctrl/Cmd + K
运行主要操作
Ctrl/Cmd + Enter
格式化
Ctrl/Cmd + Shift + F
压缩
Ctrl/Cmd + Shift + M
复制输出
Ctrl/Cmd + Shift + C
打开文件
Ctrl/Cmd + Shift + O
下载输出
Ctrl/Cmd + S
关闭此对话框
Esc
打开此对话框
F1 / ?

本地数据

以下所有内容仅存储在此浏览器、此设备上。

未保存的草稿
记住选项的工具

最近打开的文件

    此设备上尚未打开任何文件。

    通过链接分享

    内容被打包在链接 # 号之后的部分。

    分享此页面上的第一个输入。

    暂无可分享的内容。

    输入

    从 URL 加载

    直接从浏览器获取 URL。

    输出

    结果将显示在此处。

    完全在您的浏览器中运行。

    关于此工具

    The types come from the same inference the schema generator uses, so the two pages agree about your document and differ only in how they write it down. A nested object becomes a named type rather than an inline one, because an inline type three levels deep is unreadable and nothing else can refer to it. Names come from the key that holds the value, singularised inside an array, and a name that is already taken gets a number so the output always compiles. A key missing from any record is marked optional with a question mark. An empty object becomes a record of unknown rather than an empty interface, and an empty array becomes an array of unknown, since the sample says nothing about what would have been inside. Numbers are all number, because TypeScript has no integer type. Switching the output language to Python writes the same inferred shape as dataclasses instead: a nested object becomes a nested class, named and de-duplicated the same way, and a field missing from some records becomes Optional with a None default, ordered after every field that is always present, since Python requires that order. Python keeps int and float separate, unlike the TypeScript output. Switching to Go writes the same shape as structs instead, each field carrying a json struct tag with the original key, so the generated code marshals back to exactly the document it came from. A field missing from some records, or sometimes explicitly null, becomes a pointer with an omitempty tag where that actually matters, since Go already treats a missing slice or map as nil without one. Go also keeps whole numbers and fractions separate, as int64 and float64. Switching to Rust writes structs with serde derives: fields are snake_cased with a serde rename attribute whenever that differs from the original key, a field missing from some records becomes Option with skip_serializing_if so it round-trips as missing rather than null, and a Rust keyword that happens to be a JSON key, like type, is escaped as a raw identifier so the output still compiles.

    使用方法

    1. Paste a document, or several records in an array, into the input pane.
    2. Pick an output language and a root name, adjust its options, then press Generate types.
    3. Copy the declarations or download them as a file.