Given a JSON string, this library will generate all the necessary Dart classes to parse and generate JSON
This library is designed to generate Flutter
friendly model classes following the flutter's doc recommendation.Extention supports for both Serializing JSON manually and Serializing JSON using code generation libraries
- When an empty array is given, it will create a
List<Null>
. Such weird behaviour should warn the user that there is no data to extract. - Equal structures are not detected yet (Equal classes are going to be created over and over).
- Properties named with funky names (like "!breaks", "|breaks", etc) or keyword (like "
this
", "break
", "class
", etc) will produce syntax errors. - Array of arrays are not supported:
[[{ "isThisSupported": false }]]
[{ "thisSupported": [{ "cool": true }] }]
- Convert json you copied in to dart model classes.
- Convert json you selected in to dart model classes.
- Convert json you copied in to code generarion libraries supported model classes. A terminal session run after convertion to generate rest parts.
- Convert json you selected in to code generarion libraries supported model classes. A terminal session run after convertion to generate rest parts.
-
Add serializing JSON using code generation libraries to
pubspec.yaml
.structure of the
pubspec.yaml
dependencies: # Your other regular dependencies here json_annotation: <latest_version> dev_dependencies: # Your other dev_dependencies here build_runner: <latest_version> json_serializable: <latest_version>
- Add the ability to compare your generated models in a better way with
Equatable
. You can check if 2 classes, that are diferent instances, are equals without a single line of extra code.
If you'd like to use Code Generation Libraries from Flutter, first of all I suggest you to add dependencies to the pubspec.yaml
file. It also can be done with this extension. You don't need to worry about it 😉.
After that you can convert your JSON
to model classes.
Then you need to run the flutter pub run build_runner build
command to generate the missing code of the models, according to Flutter documentation.
Fortunately the extension automatically opens a new terminal session and runs that command for you, yey 😄.
- Read more about flutter's doc recommendation about JSON and serialization
-
Select a valid json. Press
Ctrl + shift + P
and search forConvert from Selection
orConvert from Selection to Code Generation supported classes
. Provide a Base class name and location to save. -
Copy a valid json. Press
Ctrl +shift + P
and search forConvert from Clipboard
orConvert from Clipboard to Code Generation supported classes
. Provide a Base class name and location to save. -
Press
Ctrl + P
and search forAdd Code Generation Libraries to pubspec.yaml
and hit enter. -
Using short cuts.
You just have to select Yes
when the process of parsing your JSON to Code has started and the extension will take care of setting up the advanced code equality check in your Dart models
Convert from Clipboard (Shift + Ctrl + Alt + V
)
Convert from Selection (Shift + Ctrl + Alt + S
)
Convert from Clipboard to Code Generation supported classes (Shift + Ctrl + Alt + G
)
Convert from Selection to Code Generation supported classes (Shift + Ctrl + Alt + H
)
- Array type merging (Huge deal)
- Duplicate type prevention
- Union types
- Optional types
- Array types
Command failed: xclip -selection clipboard -o
Solution:
sudo apt-get install xclip
Happens when linux is missing clipboard packages
Special thanks to Israel Ibarra for adding equatable support. ❤️
Feel free to contact me anytime 😊