jsonc is a Go package that converts the jsonc format to standard json.

Related tags

JSON jsonc
Overview

jsonc

GoDoc

jsonc is a Go package that converts the jsonc format to standard json.

The jsonc format is like standard json but allows for comments and trailing commas, such as:

{

  /* Dev Machine */
  "dbInfo": {
    "host": "localhost",
    "port": 5432,          
    "username": "josh",
    "password": "pass123", // please use a hashed password
  },

  /* Only SMTP Allowed */
  "emailInfo": {
    "email": "[email protected]", // use full email address
    "password": "pass123",
    "smtp": "smpt.example.com",
  }

}

There's a provided function jsonc.ToJSON, which does the conversion.

The resulting JSON will always be the same length as the input and it will include all of the same line breaks at matching offsets. This is to ensure the result can be later processed by a external parser and that that parser will report messages or errors with the correct offsets.

Getting Started

Installing

To start using jsonc, install Go and run go get:

$ go get -u github.com/tidwall/jsonc

This will retrieve the library.

Example

The following example uses a JSON document that has comments and trailing commas and converts it just prior to unmarshalling with the standard Go JSON library.

data := `
{
  /* Dev Machine */
  "dbInfo": {
    "host": "localhost",
    "port": 5432,          // use full email address
    "username": "josh",
    "password": "pass123", // use a hashed password
  },
  /* Only SMTP Allowed */
  "emailInfo": {
    "email": "[email protected]",
    "password": "pass123",
    "smtp": "smpt.example.com",
  }
}
`

err := json.Unmarshal(jsonc.ToJSON(data), &config)

Performance

It's fast and can convert GB/s of jsonc to json.

Contact

Josh Baker @tidwall

License

jsonc source code is available under the MIT License.

You might also like...
A Go package for handling common HTTP JSON responses.

go-respond A Go package for handling common HTTP JSON responses. Installation go get github.com/nicklaw5/go-respond Usage The goal of go-respond is to

A simple Go package to Query over JSON/YAML/XML/CSV Data
A simple Go package to Query over JSON/YAML/XML/CSV Data

A simple Go package to Query over JSON Data. It provides simple, elegant and fast ODM like API to access, query JSON document Installation Install the

a Go package to interact with arbitrary JSON

go-simplejson a Go package to interact with arbitrary JSON Importing import github.com/bitly/go-simplejson Documentation Visit the docs on Go package

vjson is a Go package that helps to validate JSON objects in a declarative way.

vjson vjson is a Go package that helps to validate JSON objects in a declarative way. Getting Started Installing For installing vjson, use command bel

JSONata in Go Package jsonata is a query and transformation language for JSON

JSONata in Go Package jsonata is a query and transformation language for JSON. It's a Go port of the JavaScript library JSONata.

A very rudimentary JSON compare package in GO

simple_json_compare A very rudimentary JSON compare package Sample code package main import ( "fmt" "github.com/CalypsoSys/simple_json_compare" )

A Go package to interact with arbitrary JSON

go-simplejson a Go package to interact with arbitrary JSON Importing import github.com/bitly/go-simplejson Documentation Visit the docs on Go package

This is an experimental package for working with JSON-LD documents in Go

JSON-LD đź”— Simple JSON-LD in Go This is an experimental package for working with JSON-LD documents in Go. Experimental, Pre-Alpha Quality Please do no

goi - The “Quite OK Image” format encoder / decoder for Go.
goi - The “Quite OK Image” format encoder / decoder for Go.

goi - The “Quite OK Image” format encoder / decoder for Go. QOI - The “Quite OK Image” - is losslessly image format that offering speedup both compres

Owner
Josh Baker
Josh Baker
Fork of Go's standard library json encoder

A fork of the Go standard library's json encoder Why? https://github.com/golang/go/issues/6213 was proposed in 2013 but was never accepted. Difference

unchain.io 0 Nov 25, 2021
Package json implements encoding and decoding of JSON as defined in RFC 7159

Package json implements encoding and decoding of JSON as defined in RFC 7159. The mapping between JSON and Go values is described in the documentation for the Marshal and Unmarshal functions

High Performance, Kubernetes Native Object Storage 2 Jun 26, 2022
JSON Spanner - A Go package that provides a fast and simple way to filter or transform a json document

JSON SPANNER JSON Spanner is a Go package that provides a fast and simple way to

null 6 Sep 14, 2022
Jsonmask use for mask sensitive data from json format

Jsonmask use for mask sensitive data from json format Installation go get -u github.com/rkritchat/jsonmask Code example package main import ( "fmt"

rkritchat 3 Sep 16, 2022
convert JSON of a specific format to a type structure(Typescript type or more)

json2type convert JSON of a specific format to a type structure(Typescript type or more) Quick Start CLI Install use go tool install go install github

Kim 3 Mar 28, 2022
Senml-go - a Golang module for the JSON-based SenML sensor data format

ThingWave SenML module for Golang This is a Golang module for the JSON-based Sen

ThingWave 0 Jan 2, 2022
Get JSON values quickly - JSON parser for Go

get json values quickly GJSON is a Go package that provides a fast and simple way to get values from a json document. It has features such as one line

Josh Baker 11.6k Dec 28, 2022
JSON diff library for Go based on RFC6902 (JSON Patch)

jsondiff jsondiff is a Go package for computing the diff between two JSON documents as a series of RFC6902 (JSON Patch) operations, which is particula

William Poussier 215 Dec 4, 2022
Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Masaaki Goshima 2k Jan 6, 2023
Json-go - CLI to convert JSON to go and vice versa

Json To Go Struct CLI Install Go version 1.17 go install github.com/samit22/js

Samit Ghimire 7 Jul 29, 2022