json5

package module
v0.0.0-...-8f6780e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2016 License: MIT Imports: 2 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(src []byte, v interface{}) error

Unmarshal parses the JSON5-encoded data `src` and stores the result in the value pointed to by v.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址