Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pacifio/json2dart
A CLI tool to help generate dart classes from json returned from API
https://github.com/pacifio/json2dart
cli code-generation dart flutter flutter-tool json-serializer
Last synced: 5 days ago
JSON representation
A CLI tool to help generate dart classes from json returned from API
- Host: GitHub
- URL: https://github.com/pacifio/json2dart
- Owner: pacifio
- License: mit
- Created: 2021-07-27T09:15:56.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-04T10:36:03.000Z (over 3 years ago)
- Last Synced: 2024-08-22T23:43:11.230Z (3 months ago)
- Topics: cli, code-generation, dart, flutter, flutter-tool, json-serializer
- Language: Dart
- Homepage: https://pub.dev/packages/json2dartc
- Size: 52.3 MB
- Stars: 40
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## 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](https://github.com/javiercbk/json_to_dart) ! 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
- [x] Null safety support
- [ ] Tool itself written with null safety
- [ ] Private memmbers option
- [ ] Option to load json from a file