A CLI tool to help generate dart classes from json

  Command Line, Generator, Json

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")
Optionrequireddefaultexamplenote
-utruerequired fieldhttps://reqres.in/api/users
-efalsedatait’s used for special access in json data , e.g data.data will access nested data object within data object
-nfalse‘AutoGenerated’Example
-hfalse{}access-token=01234,foo=bar
-mfalseGETGET/POST

Upcoming plans

  •  Null safety support
  •  Tool itself written with null safety
  •  Private memmbers option
  •  Option to load json from a file

Contribute Json 2 Dart Command line utility on GitHub

https://github.com/pacifio/json2dart