Now you do not need to Understand your JSON Structure and create your model manually. Here is a utility to convert your JSON into model to do that. You just need to paste your JSON in JSON field. First it will check it JSON is valid, then convert it into model. It will create different file for each class.
How to use JSONExport:
To use this tool, you first need to install it from here.
If you receive any alert like given below then open your System Preferences > Security & Privacy.
Now click on Open Anyway. It will open this app in your system.
If you want to customise it you can download the source code from github. Open this in Xcode and run the application.
Now Open this app and enter your JSON or import .json file here:
It will convert your JSON into model according to selected language. It will give you given options for language.
These are supported Languages:
- Java for Android
- Java for Realm Android
- Java GSON for Android
- Swift Classes
- Swift Classes for SwiftyJSON library
- Swift Classes for Realm
- Swift – CoreData
- Swift Structures
- Swift Structures for Gloss
- Swift Mappable Classes for (Swift 3) ObjectMapper
- Swift Structures for Unbox
- Objective-C – iOS.
- Objective-C – MAC.
- Objective-C – CoreData.
- Objective-C for Realm iOS.
Here you can see your model in second window. It will name your class as property name and first class will be named as BaseClass. Here are some More option for you at bottom.
Root class name: To change base class name Enter your Class Name in Root class name field.
Classes Prefix: If you want to add some prefix before the class name, enter here.
Parent class name: If you want to inherit your all model classes with a single class, Enter the name of class in that field.
There are more options:
- If you want to create constructor in each model class, select Constructors Check box.
- If you want to add Utility methods in model classes, then select Utility Methods Check box.
Now your model is ready to use. Use just have to put it on right place. There is button “Save” in bottom right corner. Save your file in your project and use then.
Save your time and reduce efforts by using JSONExport. 🙂