Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/disposaboy/jsonconfigreader
https://github.com/disposaboy/jsonconfigreader
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/disposaboy/jsonconfigreader
- Owner: DisposaBoy
- License: mit
- Created: 2012-02-11T09:16:06.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2020-11-29T17:28:55.000Z (about 4 years ago)
- Last Synced: 2025-01-03T12:09:15.045Z (9 days ago)
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 48
- Watchers: 5
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/DisposaBoy/JsonConfigReader.svg?branch=master)](https://travis-ci.org/DisposaBoy/JsonConfigReader)
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)
}