https://github.com/ztomz/json2dart
https://github.com/ztomz/json2dart
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ztomz/json2dart
- Owner: zTomz
- License: mit
- Created: 2022-10-08T11:28:46.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-08T11:35:35.000Z (over 3 years ago)
- Last Synced: 2025-02-22T09:42:27.467Z (over 1 year ago)
- Language: Dart
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Json2Dart
Json2Dart is a package to converts your map (json) to a String, wich is the output Dart code. You can write the String to a file or put it in a text widget.
## How to use
```Dart
import 'dart:convert';
import 'dart:io';
import 'package:json2dart/json2dart.dart';
void main(List args) {
// Your json String
String jsonString = '''
{
"weather": "sunny",
"clouds": "no",
"time": "11.30",
"sports you can do": [
"running",
"hiking",
"biking"
],
"any map": {
"key 1": "value 1",
"key 2": "value 2"
}
}''';
// Decode the json String to a Map
Map jsonData = jsonDecode(jsonString);
// Compile the json to Dart code
final String dartCode = Json2Dart.compileJson2Dart(jsonData, null);
// Output
print("Json:");
print(jsonData);
print("");
print("Dart:");
print(dartCode);
// Or write to a file
File dartCodeFile = File("${Directory.current.path}/example/generated_json.dart");
dartCodeFile.writeAsString(dartCode);
}
```