JSONExport: JSON to Model

DZone 's Guide to

JSONExport: JSON to Model

We look at how the open source JSONExport npm package can make creating models from JSON data much easier. Read on to get started!

· Web Dev Zone ·
Free Resource


With JSONExport, 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 into the JSON field. First, it will check that JSON is valid and then it will convert it into a model. It will create different files 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 customize 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 the .json file here:

It will convert your JSON into models according to the selected language. It will give you the given options for the language.

These are the supported languages:

  1. Java for Android
  2. Java for Realm Android
  3. Java GSON for Android
  4. Swift Classes
  5. Swift Classes for SwiftyJSON library
  6. Swift Classes for Realm
  7. Swift - CoreData
  8. Swift Structures
  9. Swift Structures for Gloss
  10. Swift Mappable Classes for (Swift 3) ObjectMapper
  11. Swift Structures for Unbox
  12. Objective-C - iOS.
  13. Objective-C - MAC.
  14. Objective-C - CoreData.
  15. Objective-C for Realm iOS.

Here you can see your model in a second window. It will give your class as a property name and the first class will be named BaseClass. Here are some more options for you at the 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 it 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 a constructor in each model class, select the Constructors check box.
  • If you want to add Utility methods in the model classes, then select the Utility Methods check box.

Now your model is ready to use. Use just have to put it in the right place. There is a "Save" button at bottom right corner. Save your file in your project.

Save your time and reduce efforts by using JSONExport.

json ,web dev ,npm package ,jsonexport ,tutorial

Published at DZone with permission of Chanchal Chauhan . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}