remove comment from the json file.
- Only line comment
//
is supported. - Multi-line comment
/**/
is not supported.
please find the example in example folder
main.go
package main
import (
"encoding/json"
"fmt"
"os"
"path"
"github.com/wuxiangzhou2010/jsonuncommenter"
)
type seeds struct {
Seeds []string `json:"seeds"`
Name string `json:"name"`
}
func main() {
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
f, err := os.Open(path.Join(cwd, `config.json`))
if err != nil {
panic(err)
}
defer f.Close()
newReader := jsonuncommenter.RemoveComment(f)
jsonParser := json.NewDecoder(newReader)
var s seeds
jsonParser.Decode(&s)
fmt.Printf("%+v", s)
}
config.json
{
"seeds": [
"https://www.baidu.com" // http下载
//
// "https://v.qq.com"
],
"name": "test"
}
output
$ go run main.go
{Seeds:[http://t66y.com/thread0806.php?fid=16] Name:test}
reference