json2dartc 1.0.0 copy "json2dartc: ^1.0.0" to clipboard
json2dartc: ^1.0.0 copied to clipboard

A CLI tool to help generate dart classes from json returned from API

Json 2 Dart Command line utility #

Important note #

There is already a package called json2dart so this package will be called json2dartc !

This project was made using javiercbk's json_to_dart package ! This CLI was made to directly convert JSON stuctures into Dart classes . I personally don't like build runners and json serializers so I made this for my workflow . Feel free to open issues and submit PRs .

How to use #

Install this via pub

pub global activate json2dartc

Example #

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

Null safety #

To turn on null safe code generation , add the flag --null-safe , Example :

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

Options #

-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")
Option required default example note
-u true required field https://reqres.in/api/users
-e false '' data it's used for special access in json data , e.g data.data will access nested data object within data object
-n false 'AutoGenerated' Example
-h false {} access-token=01234,foo=bar
-m false GET GET/POST

Upcoming plans #

  • ✅ Null safety support
  • ❌ Tool itself written with null safety
  • ❌ Private memmbers option
  • ❌ Option to load json from a file
7
likes
30
pub points
0%
popularity

Publisher

unverified uploader

A CLI tool to help generate dart classes from json returned from API

Repository

License

MIT (license)

Dependencies

args, dart_style, http, json_ast

More

Packages that depend on json2dartc