Skip to content

wuxiangzhou2010/jsonuncommenter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Json uncommenter

remove comment from the json file.

  1. Only line comment // is supported.
  2. Multi-line comment /**/ is not supported.

Example

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

About

Remove line comments before unmarshal

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages