🟣 JSON 转 Kotlin 数据类JSON to Kotlin Data Class
粘贴 JSON 自动生成 Kotlin data class,可选 kotlinx.serialization、Gson 或 Moshi 注解;嵌套对象和数组生成独立类,缺失或为 null 的字段自动变成可空类型。Paste JSON to generate Kotlin data classes with optional kotlinx.serialization, Gson or Moshi annotations; nested objects and arrays become their own classes and missing or null fields become nullable.
使用说明与常见问题How-to & FAQ
「JSON 转 Kotlin 数据类」是什么?What is the JSON to Kotlin Data Class tool?
粘贴 JSON 自动生成 Kotlin data class,可选 kotlinx.serialization、Gson 或 Moshi 注解;嵌套对象和数组生成独立类,缺失或为 null 的字段自动变成可空类型。Paste JSON to generate Kotlin data classes with optional kotlinx.serialization, Gson or Moshi annotations; nested objects and arrays become their own classes and missing or null fields become nullable.
如何使用「JSON 转 Kotlin 数据类」?How do I use the JSON to Kotlin Data Class?
把 JSON 粘贴到上方输入框,选择注解风格并填写根类名,下方会实时生成 Kotlin 代码,点击「复制结果」即可。例如 {"user_name":"Alice"} 会生成 val userName: String,并带上 @SerialName("user_name")。Paste JSON into the input, pick an annotation style and root class name, and the Kotlin code appears below — click "Copy result". For example {"user_name":"Alice"} becomes val userName: String with @SerialName("user_name").
字段名里的下划线会怎么处理?What happens to snake_case keys?
会转成 Kotlin 惯用的驼峰命名(user_name → userName),并用所选库的注解保留原始 JSON 键名,序列化和反序列化都能对上。They become idiomatic camelCase (user_name → userName) and the chosen library's annotation keeps the original JSON key, so (de)serialization still matches.
什么时候字段会变成可空类型?When does a field become nullable?
字段值为 null,或在数组里的某些对象中缺失时,会生成「类型? = null」;超过 Int 范围的整数会用 Long。When a value is null or the key is missing from some objects in an array, the field becomes "Type? = null"; integers beyond the Int range use Long.
「JSON 转 Kotlin 数据类」免费吗?数据会上传吗?Is the JSON to Kotlin Data Class free? Is my data uploaded?
「JSON 转 Kotlin 数据类」完全免费,无需注册或安装,手机和电脑都能用;所有处理都在你的浏览器本地完成,输入的内容和文件不会上传到服务器。The JSON to Kotlin Data Class is completely free with no sign-up or install and works on phones and desktops; everything runs locally in your browser and nothing you enter is uploaded.