DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. JSONExport: JSON to Model

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!

Chanchal Chauhan user avatar by
Chanchal Chauhan
·
Oct. 07, 18 · Tutorial
Like (4)
Save
Tweet
Share
8.12K Views

Join the DZone community and get the full member experience.

Join For Free

JSONExport

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

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

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Do Not Forget About Testing!
  • How To Create and Edit Excel XLSX Documents in Java
  • Using the PostgreSQL Pager With MariaDB Xpand
  • AIOps Being Powered by Robotic Data Automation

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: