https://github.com/hedhyw/jsoncjson
JSONC (json with comments) to JSON translator for Golang.
https://github.com/hedhyw/jsoncjson
go golang json jsonc
Last synced: over 1 year ago
JSON representation
JSONC (json with comments) to JSON translator for Golang.
- Host: GitHub
- URL: https://github.com/hedhyw/jsoncjson
- Owner: hedhyw
- License: mit
- Created: 2020-09-04T16:27:18.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-01T06:46:59.000Z (over 2 years ago)
- Last Synced: 2025-03-18T17:05:52.273Z (over 1 year ago)
- Topics: go, golang, json, jsonc
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JSONcJSON

[](https://goreportcard.com/report/github.com/hedhyw/jsoncjson)
[](https://coveralls.io/github/hedhyw/jsoncjson?branch=master)
[](https://pkg.go.dev/github.com/hedhyw/jsoncjson?tab=doc)
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:
```jsonc
{
/*
JSONcJSON
=^._.^= ∫
*/
"Hello": "world" // In-line comments are also supported.
}
```
to a valid JSON:
```json
{
"Hello": "world"
}
```
## Installing:
```sh
go get github.com/hedhyw/jsoncjson
```
## Usage example:
More [examples](./example_test.go).
```go
// 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].
```