https://github.com/fluttercandies/json_to_dart_library
json_to_dart_library
https://github.com/fluttercandies/json_to_dart_library
Last synced: 2 months ago
JSON representation
json_to_dart_library
- Host: GitHub
- URL: https://github.com/fluttercandies/json_to_dart_library
- Owner: fluttercandies
- License: mit
- Created: 2025-05-23T03:00:31.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-09-06T13:20:07.000Z (9 months ago)
- Last Synced: 2025-09-06T15:21:19.700Z (9 months ago)
- Language: Dart
- Size: 70.3 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## The library to convert json to dart code
The library for [https://github.com/fluttercandies/JsonToDart/Flutter/json_to_dart](https://github.com/fluttercandies/JsonToDart/tree/master/Flutter/json_to_dart)
## simple used
```dart
Future main(List args) async {
DartObject? dartObject = await jsonToDartController.jsonToDartObject(
json: '''{"data":[{"a":1}],"msg":"s","code":0}''',
);
var errors = jsonToDartController.getErrors();
if (errors.isNotEmpty) {
print('Errors found:');
for (var error in errors) {
print(error);
}
return;
}
if (dartObject != null) {
var dartCode = jsonToDartController.generateDartCode(dartObject);
File('output.dart').writeAsStringSync(dartCode!);
print('Dart code generated successfully:');
}
}
```
## custom
you can define the config and DartObject/DartProperty to generate your own dart style code.
you can see bin/custom.dart to see more info.