File: README.md

package info (click to toggle)
golang-github-disposaboy-jsonconfigreader 0.0~git20171218.5ea4d0d-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports, buster, buster-backports, forky, sid, trixie
  • size: 80 kB
  • sloc: makefile: 2
file content (50 lines) | stat: -rw-r--r-- 1,081 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
[![Build Status](https://travis-ci.org/DisposaBoy/JsonConfigReader.svg?branch=master)](https://travis-ci.org/DisposaBoy/JsonConfigReader)

<hr/>




JsonConfigReader is a proxy for [golang's io.Reader](http://golang.org/pkg/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)
	}