Giter VIP home page Giter VIP logo

json2model's Introduction

Json2Model

About

Json2Model (aka Broccoli) is a small little tool to help to automate the creation of Models from JSON files so you do not have to suffer :)

Goals

  • Ability to create Model classes from the files.
  • Nested classes will be created as well.
  • Multi-language support (programing language anyway).
  • Data type deduction.

Install

  • Download or clone repository.
  • Navigate to folder /Json2Model/bin/
  • Run the j2m.sh from the command line.

Note: Make sure that the file has permission to run in your computer.

Documentation

  • Navigate to he cloned/downloaded repository
  • Go to folder Json2Model/doc
  • Open the file /overview-summary.html to read the documentation
  • Command line documentation.
usage: j2m [-f <FILE>] [-h] [-lang <LANG>] [-o <DIR>]
A very small tool for people to get things done fast! :)

 -f,--file <FILE>          The file to be processed.
 -h,--help                 Help
 -lang,--language <LANG>   The language for the file output.
                           Allowed languages:
                           [C_SHARP, JAVA, JAVA_SCRIPT, OBJECTIVE_C,
                           SWIFT]
 -o,--out <DIR>            The directory where to place the processed
                           files. If ommited the same DIR as 'file' is
                           used
Enjoy

User Guides

I want to get a Model 'Input' file from input.json file to follow MVC patters.

input.json contains:

{
	"customer":{
		"firstName": "John",
		"lastName": "Doe"
	},
	"addresses": [
		{
			"street": "Faraway Creek",
			"number": 1234,
			"city":	"Never-land"
		}
	],
	"balance": 23234.23,
	"active": true
}
  • Just run this to test.
./j2m.sh -f "myDirectory/Box.json" -lang=java -o "/myDirectory/target/"
  • New files was created in the specified directory:
public class Input {

	private ArrayList<Address> addresses;
	private double balance;
	private boolean active;
	private Customer customer;

	public Input(ArrayList<Address> addresses, double balance, boolean active, Customer customer) {
		super();
		this.addresses = addresses;
		this.balance = balance;
		this.active = active;
		this.customer = customer;
	}

	public void load() {
		//TODO: Needs to be implemented.
	}

	public ArrayList<Address> getAddresses() {
		return addresses;
	}
	public void setAddresses(ArrayList<Address> addresses) {
		this.addresses = addresses;
	}
	public double getBalance() {
		return balance;
	}
	public void setBalance(double balance) {
		this.balance = balance;
	}
	public boolean isActive() {
		return active;
	}
	public void setActive(boolean active) {
		this.active = active;
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
}

public class Customer {

	private String firstName;
	private String lastName;

	public Customer(String firstName, String lastName) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
	}

	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
}

public class Address {

	private int number;
	private String city;
	private String street;

	public Address(int number, String city, String street) {
		super();
		this.number = number;
		this.city = city;
		this.street = street;
	}

	public int getNumber() {
		return number;
	}
	public void setNumber(int number) {
		this.number = number;
	}
	public String getCity() {
		return city;
	}
	public void setCity(String city) {
		this.city = city;
	}
	public String getStreet() {
		return street;
	}
	public void setStreet(String street) {
		this.street = street;
	}
}

Report a Bug or Contribute

  • Navigate to the bug section tab on GitHub.

  • Create a new Issue. If you are not sure how to create a new issue follow this link for instructions Creating an issue

  • For new language support include sample of the class/structure in the body of the issue. Use this JSON text:

{
	"customer":{
		"firstName": "John",
		"lastName": "Doe"
	},
	"addresses": [
		{
			"street": "Faraway Creek",
			"number": 1234,
			"city":	"Never-land"
		}
	],
	"balance": 23234.23,
	"active": true
}

License

We are released under the Apache 2.0 license.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

json2model's People

Contributors

sparkmuse avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.