GithubHelp home page GithubHelp logo

json2java's Introduction

This repository contains a code generator that reads an input JSON file and generates corresponding Java classes like the following example:

{
  "Student": [
    {
      "name": "Bob",
      "id": "12341234",
      "phone": "9999999",
      "Course": [
        {
          "code": "CI1061",
          "name": "Embedded Systems"
        },
        {
          "code": "CI1057",
          "name": "Programming 2"
        }
      ]
    },
    {
      "name": "Alice",
      "id": "123456",
      "phone": "8888888",
      "Course": [
        {
          "code": "CI1061",
          "name": "Embedded Systems"
        },
        {
          "code": "CI1056",
          "name": "Programming 1"
        }
      ]
    }
  ]
}

The generated Java code based on the above JSON file is the following:

import java.util.ArrayList;
class Course {
	String code;
	String name;
}
class Student {
	String name;
	String id;
	String phone;
	ArrayList<Course> course;
}
public class Program {
	public static void main (String args[]){
	}
}

In order to run the generator, use it as follows:

python3 jsonToJava.py <input.json>

The program generates the Java code into the Program.java file, in the current directory.

Limitations

This generator has the following limitations:

  • the input file is not validated
  • the names of the list fields are not pluralized
  • it only accepts a subset of all JSON files - only those whose structure resamble the example in this file.

License

This project is released under the MIT License. For more information check out the license file.

json2java's People

Contributors

thaysolis avatar

Stargazers

Felipe Michels Fontoura avatar

Watchers

 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.