GithubHelp home page GithubHelp logo

j2k's Introduction

J2K

J2K means "Json sample to Kotlin".

Usage

J2K is simple Kotlin Gradle project. You have 2 options.

  1. Clone this repo and run J2K main method
  2. Use .jar

J2K have 3 args.

  1. path to json file
  2. Kotlin class name you want
  3. path to out file (optional)

First, make .json file you want to convert.

{
  "id": "acb12345",
  "users": [
    {"id": 1000, "name": "joe"},
    {"id": 1001, "name": "smith"}
  ],
  "arrowed_type": [1,2,3],
  "transaction_fee": 0.3
}

Next, run J2K as below

java -jar ./build/libs/J2K-1.0-SNAPSHOT.jar sample.json SampleClass

You see Kotlin data class in stdout.

import kotlin.Double
import kotlin.Long
import kotlin.String
import kotlin.collections.List

data class MyClass(
  val id: String,
  val users: List<User>,
  val arrowedType: List<Long>,
  val transactionFee: Double
)

data class User(
  val id: Long,
  val name: String
)

Rule, Constraint

  • if json object key is aa_bb_cc then class name for object is AaBbCc.
  • if json array key is aa_bb_ccs then class name for element in array is AaBbCc.
  • if json key is aa_bb_ccs then property name is aaBbCbc.
  • if json value is null then property type is String.
  • json number is converted to Long or Double.

Tech

License

Apache-2.0

j2k's People

Contributors

n-seki avatar

Stargazers

 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.