Skip to content

Latest commit

 

History

History
58 lines (45 loc) · 1.45 KB

README.md

File metadata and controls

58 lines (45 loc) · 1.45 KB

JSONcJSON

Version Go Report Card Coverage Status PkgGoDev

The library provides a JSONC (json with comments) to JSON streamer. It supports multiline comments ( /* Comment */) and one-line comments ( // Comment ). It processes chunks of 512 bytes in place.

For example, it translates JSON with comments:

{
    /*
        JSONcJSON
        =^._.^= ∫
    */
    "Hello": "world" // In-line comments are also supported.
}

to a valid JSON:

{
    "Hello": "world"
}

Installing:

go get github.com/hedhyw/jsoncjson

Usage example:

More examples.

// Converting jsonc to json and decoding.

const in = `
{
    "Hello": "world"
    /* Perhaps the truth depends on a walk around the lake. */
}
`

// The reader can be anything.
// For example: file, strings.NewReader(), bytes.NewReader(), ...
var r = jsoncjson.NewReader(strings.NewReader(in))

var data map[string]interface{}
_, = json.NewDecoder(r).Decode(&data)

fmt.Printf("%+v\n", data) // map[Hello:world].