dnscontrol/vendor/github.com/DisposaBoy/JsonConfigReader
Tom Limoncelli 16d0043cce
Switch from govendor to go modules. (#587)
Thanks to @BenoitKnecht for leading the way on this.
2020-01-18 14:40:28 -05:00
..
.travis.yml Switch from govendor to go modules. (#587) 2020-01-18 14:40:28 -05:00
AUTHORS.md Update github.com/DisposaBoy/JsonConfigReader (#514) 2019-06-30 09:05:38 -04:00
LICENSE.md migrate code for github 2016-08-22 18:31:50 -06:00
reader.go Update github.com/DisposaBoy/JsonConfigReader (#514) 2019-06-30 09:05:38 -04:00
README.md Update github.com/DisposaBoy/JsonConfigReader (#514) 2019-06-30 09:05:38 -04:00

Build Status


JsonConfigReader is a proxy for golang's io.Reader that strips line comments and trailing commas, allowing you to use json as a reasonable config format.

Comments start with // and continue to the end of the line. Multiline comments are also supported with /* and */.

If a trailing comma is in front of ] or } it will be stripped as well.

Given settings.json

{
	"key": "value", // k:v

	// a list of numbers
	"list": [1, 2, 3],

	/* 
	a list of numbers
	which are important
	*/
	"numbers": [1, 2, 3],
}

You can read it in as a normal json file:

package main

import (
	"encoding/json"
	"fmt"
	"github.com/DisposaBoy/JsonConfigReader"
	"os"
)

func main() {
	var v interface{}
	f, _ := os.Open("settings.json")
	// wrap our reader before passing it to the json decoder
	r := JsonConfigReader.New(f)
	json.NewDecoder(r).Decode(&v)
	fmt.Println(v)
}