Code Monkey home page Code Monkey logo

jsongenerator's Introduction

1. Standart JSON Generator library

A JSON generator library to serialize objects into JSON formated text implemented in Kotlin

Custom Annotations

@JJSONCustomField: Used to apply a custom property name in the final JSON string

@JSONExcludeItem: Used to exclude a given class property is to be ignored when generating the JSON string

How to use

  1. Create a JSONInspector instance
  2. (Optional) Add one of the library`s annotations to the desired object
  3. Invoke either the .objectToJSON or .objectToJSONPrettyPrint acording to the desired results

Examples

Example 1:

Classes:

class Cars(
        val brand: String,
        val model: String,
        val year: Int)

class Contacts(val email: String,
               val phone: String)

class RelationShipStatus(
        val maritalStatus: String,
        val birthday: String)

class PetOwner(
        val owner: String,
        val pets: MutableList<*>)

class Boss(
        val bossName: String,
        @JSONExcludeItem
        val role: String,
        val contacts: Contacts?,
        val extras: MutableList<*>?
)

Code:

val contacts = Contacts("[email protected]", "999888777")
val relationShipStatus = RelationShipStatus("Married", "09-12-1979")
val car = Cars("Cloudy", "Biggy", 2009)
val extras: MutableList<Any> = mutableListOf(relationShipStatus, car)
val boss = Boss("Pedro", "Project Manager", contacts, extras)
val jsonObject = JSONInspector()

JSON output:

{
	"bossName": "Pedro",
	"Contacts": {
		"email": "[email protected]",
		"phone": "999888777"
	},
	"extras": [{
			"birthday": "09-12-1979",
			"maritalStatus": "Married"
		},
		{
			"brand": "Cloudy",
			"model": "Biggy",
			"year": 2009
		}
	]
}

Example 2:

val contacts = Contacts("[email protected]", "999888777")
val relationShipStatus = RelationShipStatus("Married", "09-12-1978")
val car = Cars("Cloudy", "Biggy", 2008)
val extras: MutableList<Any> = mutableListOf(relationShipStatus, car)
val address: MutableList<Any> = mutableListOf("Rua da vida", "Aqui não passas")
val person = Person("Miguel", 23, 1.79, 65.4f, true,null, contacts, address, extras, 'c')

val jsonVisitor = JSONInspector()
jsonVisitor.objectToJSONPrettyPrint(person)

JSON output:

{
	"address": [
		"Rua da vida",
		"Aqui não passas"
	],
	"age": 23,
	"Contacts": {
		"email": "[email protected]",
		"phone": "999888777"
	},
	"extras": [{
			"birthday": "09-12-1978",
			"maritalStatus": "Married"
		},
		{
			"brand": "Cloudy",
			"model": "Biggy",
			"year": 2008
		}
	],
	"height": 1.79,
	"id": "c",
	"isWonderfulPerson": "true",
	"name": "Miguel",
	"occupation": "null",
	"weight": 65.4
}

2. GUI

In order to enhance the visual experience of a json string, a simple GUI was developed to re-create the json generated from a given object

Functionalities

  • Get node depth
  • Search for a keyword
  • Interact with the json created

3. JSON Plugin

To allow customization, the GUI enables the creation of custom plugins

GUI customizations

  • Name the GUI window
  • Define the GUI window size and layout
  • Define a custom rule to customize each visual json node

Plugin Actions

Custom actions can be created to add extra functionalities, like:

  • Editing a node name
  • Export the json generated as a file

Plugin example

image

jsongenerator's People

Contributors

migueldordio avatar

Watchers

 avatar  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.