Code Monkey home page Code Monkey logo

jsonutils's Introduction

jsonutils

Converter for JSON data to a Go struct or a Java class for GSON

go get github.com/bashtian/jsonutils/cmd/jsonutil

You can print the structure of a JSON from a URL

jsonutil https://api.github.com/repos/bashtian/jsonutils

or from a file

jsonutil -f file.json

or from stdin

echo '{"some": "data"}' | jsonutil

If you want to print example data as comments, use the -x parameter

jsonutil -x https://api.github.com/repos/bashtian/jsonutils

You can also print Java code

jsonutil -j https://api.github.com/repos/bashtian/jsonutils

Example

JSON

{
    "firstName": "John",
    "lastName": "Smith",
    "age": 25,
    "balance": 123.45,
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": "10021"
    },
    "phoneNumber": [
        {
            "type": "home",
            "number": "212 555-1234",
            "last_call": "2013-01-10T05:27:07Z"
        },
        {
            "type": "fax",
            "number": "646 555-4567",
            "last_call": "2013-01-10T05:27:07Z"
        }
    ],
    "tags": ["music","video"]
}

Go

jsonutil -x -c=false -f Example.json
type Example struct {
	Address struct {
		City          string `json:"city"`          // New York
		PostalCode    string `json:"postalCode"`    // 10021
		State         string `json:"state"`         // NY
		StreetAddress string `json:"streetAddress"` // 21 2nd Street
	} `json:"address"`
	Age         int64   `json:"age"`       // 25
	Balance     float64 `json:"balance"`   // 123.45
	FirstName   string  `json:"firstName"` // John
	LastName    string  `json:"lastName"`  // Smith
	PhoneNumber []struct {
		LastCall string `json:"last_call"` // 2013-01-10T05:27:07Z
		Number   string `json:"number"`    // 212 555-1234
		Type     string `json:"type"`      // home
	} `json:"phoneNumber"`
	Tags []string `json:"tags"` // music
}
jsonutils -f Example.json
type Example struct {
	Address struct {
		City          string `json:"city"`
		PostalCode    int64  `json:"postalCode,string"`
		State         string `json:"state"`
		StreetAddress string `json:"streetAddress"`
	} `json:"address"`
	Age         int64   `json:"age"`
	Balance     float64 `json:"balance"`
	FirstName   string  `json:"firstName"`
	LastName    string  `json:"lastName"`
	PhoneNumber []struct {
		LastCall time.Time `json:"last_call"`
		Number   string    `json:"number"`
		Type     string    `json:"type"`
	} `json:"phoneNumber"`
	Tags []string `json:"tags"`
}

jsonutils's People

Contributors

bashtian avatar josharian avatar bryant1410 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.