Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shiburagi/jsontodart
VS Code Extension
https://github.com/shiburagi/jsontodart
dart dart-model flutter json jsontodart vscode-extension
Last synced: about 1 month ago
JSON representation
VS Code Extension
- Host: GitHub
- URL: https://github.com/shiburagi/jsontodart
- Owner: shiburagi
- Created: 2021-01-17T18:09:46.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-12-09T18:32:51.000Z (almost 2 years ago)
- Last Synced: 2023-03-10T04:22:49.151Z (over 1 year ago)
- Topics: dart, dart-model, flutter, json, jsontodart, vscode-extension
- Language: TypeScript
- Homepage:
- Size: 1.25 MB
- Stars: 8
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# jsontodart
Demo : https://jsontodart.zariman.dev/
## How to use
### Method 1
1) Copy JSON
2) Open ```Command Pallete```, and find ```JsonToDart: Convert JSON from Clipboard```
3) Fill the box, select the option
4) Done### Method 2
1) Copy JSON
2) Right click on folder or dart file
3) Click ```Convert JSON from Clipboard Here```
4) Fill the box, select the option
6) Done### More Configuration
To handle **null** value on generated model, you can define/change data type on pubspec.yamlExample:
```yaml
jsonToDart:
nullValueDataType: String #default: dynamic
```## Sample
```json
{
"data": {
"id": 2,
"email": "[email protected]",
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://reqres.in/img/faces/2-image.jpg"
},
"support": {
"url": "https://reqres.in/#support-heading",
"text": "To keep ReqRes free, contributions towards server costs are appreciated!"
}
}
```Output:
```dart
class User {
Data? data;
Support? support;User({this.data, this.support});
User.fromJson(Map json) {
this.data = json["data"] == null ? null : Data.fromJson(json["data"]);
this.support = json["support"] == null ? null : Support.fromJson(json["support"]);
}Map toJson() {
final Map data = new Map();
if(this.data != null)
data["data"] = this.data?.toJson();
if(this.support != null)
data["support"] = this.support?.toJson();
return data;
}
}class Support {
String? url;
String? text;Support({this.url, this.text});
Support.fromJson(Map json) {
this.url = json["url"];
this.text = json["text"];
}Map toJson() {
final Map data = new Map();
data["url"] = this.url;
data["text"] = this.text;
return data;
}
}class Data {
int? id;
String? email;
String? firstName;
String? lastName;
String? avatar;Data({this.id, this.email, this.firstName, this.lastName, this.avatar});
Data.fromJson(Map json) {
this.id = json["id"];
this.email = json["email"];
this.firstName = json["first_name"];
this.lastName = json["last_name"];
this.avatar = json["avatar"];
}Map toJson() {
final Map data = new Map();
data["id"] = this.id;
data["email"] = this.email;
data["first_name"] = this.firstName;
data["last_name"] = this.lastName;
data["avatar"] = this.avatar;
return data;
}
}```
## Customize (pubspec.yaml)
```yaml
jsonToDart:
outputFolder: lib/models #default: lib/
typeChecking: true #default: undefined (Select from picker)
nullValueDataType: String #default: dynamic
nullSafety: false #default: true
copyWithMethod: true #default: false
mergeArrayApproach: false #default: true
#default: false,
#if true, value = (json[key] as num).toInt() or value = (_data[key] as num).toDouble()
#if false, value = json[key]
#if "ask", selection popup will apear before parse json
checkNumberAsNum: true # true, false, "ask"
```