🌳 JSON 转 Elm 类型与解码器JSON to Elm Decoder
根据 JSON 生成 Elm 0.19 的 type alias 记录类型、Json.Decode 解码器(基于 elm-json-decode-pipeline)和 Json.Encode 编码器,可空或缺失字段生成 Maybe。Generate Elm 0.19 record type aliases, Json.Decode decoders (using elm-json-decode-pipeline) and Json.Encode encoders from JSON, with Maybe for nullable or missing fields.
使用说明与常见问题How-to & FAQ
「JSON 转 Elm 类型与解码器」是什么?What is the JSON to Elm Decoder tool?
根据 JSON 生成 Elm 0.19 的 type alias 记录类型、Json.Decode 解码器(基于 elm-json-decode-pipeline)和 Json.Encode 编码器,可空或缺失字段生成 Maybe。Generate Elm 0.19 record type aliases, Json.Decode decoders (using elm-json-decode-pipeline) and Json.Encode encoders from JSON, with Maybe for nullable or missing fields.
如何使用「JSON 转 Elm 类型与解码器」?How do I use the JSON to Elm Decoder?
粘贴 JSON 并填写模块名(根类型名),下方生成完整的 Elm 模块。需要先安装依赖:elm install NoRedInk/elm-json-decode-pipeline。Paste JSON and set the module (root type) name to get a complete Elm module. Install the dependency first: elm install NoRedInk/elm-json-decode-pipeline.
为什么要用 elm-json-decode-pipeline?Why elm-json-decode-pipeline?
Elm 核心库的 Decode.map 最多只支持 8 个字段,用管道写法(|> required / optional)可以解码任意数量的字段,代码也更易读。The core Decode.map functions stop at 8 fields; the pipeline style (|> required / optional) handles any number of fields and reads better.
缺失的字段会怎么处理?How are missing fields handled?
在样本中可能缺失或为 null 的字段会生成 Maybe 类型,并用 optional ... (Decode.nullable ...) Nothing 解码,键不存在或值为 null 都会得到 Nothing。Fields that may be missing or null become Maybe and decode with optional ... (Decode.nullable ...) Nothing, so either a missing key or null gives Nothing.
「JSON 转 Elm 类型与解码器」免费吗?数据会上传吗?Is the JSON to Elm Decoder free? Is my data uploaded?
「JSON 转 Elm 类型与解码器」完全免费,无需注册或安装,手机和电脑都能用;所有处理都在你的浏览器本地完成,输入的内容和文件不会上传到服务器。The JSON to Elm Decoder 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.