Giter Club home page Giter Club logo

go-json5's Introduction

About

go-json5 is a JSON5 parser/unmarshaler written in Go.

Installing

Using go get

$ go get github.com/rolldever/go-json5

Example

JSON5 example (see json5.org):

{
    foo: 'bar',
    while: true,

    this: 'is a \
multi-line string',

    // this is an inline comment
    here: 'is another', // inline comment

    /* this is a block comment
       that continues on another line */

    hex: 0xDEADbeef,
    half: .5,
    delta: +10,
    // to: Infinity,   // and beyond!

    finally: 'a trailing comma',
    oh: [
        "we shouldn't forget",
        'arrays can have',
        'trailing commas too',
    ],
}

Parsing using go-json5:

package main

import (
	"fmt"
	"github.com/rolldever/go-json5"
)

func main() {
	var json5Bytes []byte = ...

	// or simply `interface{}` if you know nothing about the JSON5 source
	var obj map[string]interface{}

	if err := json5.Unmarshal(json5Bytes, &obj); err != nil {
		panic(err)
	}

	fmt.Println(obj)
}

Unmarshaling to a struct:

package main

import (
	"fmt"
	"github.com/rolldever/go-json5"
)

type SomeStruct struct {
	Foo         string   `json:"foo"`
	This        string   `json:"this"`
	Hex         int      `json:"hex"`
	StringArray []string `json:"oh"`
}

func main() {
	var json5Bytes []byte = ...

	var obj SomeStruct
	if err := json5.Unmarshal(json5Bytes, &obj); err != nil {
		panic(err)
	}

	fmt.Println(obj)
}

Full docs

See https://godoc.org/github.com/rolldever/go-json5.

Or run:

$ godoc github.com/rolldever/go-json5

License

go-json5 is distributed under the MIT License.

go-json5's People

Contributors

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