Json 2 Dart 命令行工具

一个 CLI 工具,用于帮助从 API 返回的 JSON 生成 Dart 类

重要提示

已有一个名为 json2dart 的包,所以这个包将命名为 json2dartc

example

本项目使用 javiercbk 的 json_to_dart 包 !此 CLI 工具旨在直接将 JSON 结构转换为 Dart 类。我个人不喜欢构建运行器和 JSON 序列化器,所以我为我的工作流程创建了这个。欢迎提出 issues 和提交 PR。

如何使用

通过 pub 安装

pub global activate json2dartc

示例

json2dartc -u https://reqres.in/api/users -m get -e data -n Example

空安全

要启用空安全代码生成,请添加标志 --null-safe,例如:

json2dartc -u https://reqres.in/api/users -m get -n Example --null-safe

选项

-u, --api        API Endpoint required to grab the json from
-e, --entry      Entry point for json data structure , e.g data.data will get the nested data array/object from API response
-n, --name       Name of your data class
                 (defaults to "AutoGenerated")
-h, --headers    Headers for your API endpoint
-m, --method     Method for http request , defaults to GET
                 (defaults to "GET")
选项 必需 默认值 示例 注意
-u 必填字段 https://reqres.in/api/users
-e '' data 用于 JSON 数据中的特殊访问,例如 data.data 将访问 data 对象内的嵌套数据对象
-n 'AutoGenerated' 示例
-h {} access-token=01234,foo=bar
-m GET GET/POST

即将推出的计划

  • [x] 支持空安全
  • [ ] 工具本身使用空安全编写
  • [ ] 私有成员选项
  • [ ] 从文件加载 JSON 的选项

GitHub

https://github.com/pacifio/json2dart