JSON Lint
Switch branches/tags
Nothing to show
Clone or download
Latest commit 9ff3354 Nov 29, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmd/jl fix package name Nov 28, 2018
fixtures json examples fixtures Nov 26, 2018
vendor add go mod and vendor Nov 28, 2018
.codeclimate.yml add service file Nov 28, 2018
.gitignore Initial commit Nov 26, 2018
.goreleaser.yml add service file Nov 28, 2018
.travis.yml fix git dirty state Nov 28, 2018
LICENSE Initial commit Nov 26, 2018
README.md add usage example Nov 29, 2018
go.mod add go mod and vendor Nov 28, 2018
go.sum add go mod and vendor Nov 28, 2018
jsonlint.go fix package name Nov 28, 2018
jsonlint_test.go fix package name Nov 28, 2018
wercker.yml add wercker.yml Nov 28, 2018

README.md

JSON Lint

Build Status Go Report Card GoDoc Go project version MIT Licensed

A small utility to validate, format JSON and when it has an error, if possible indicate with an arrow where the error is.

It can also be used as a Go package.

Example

cat << EOF | jl                                                                       {
    "name": "John",
    "age": 30,
    "cars": {
        "car1": "Ford",
        "car2":: "BMW",
        "car3": "Fiat"
    }
}
EOF
SyntaxError: invalid character ':' looking for beginning of value, offset: 91, row: 5, col: 16
        "car2":: "BMW",

As a package

Use as a Go package to get a better error message.

go get -u github.com/gosidekick/jsonlint
j := `{
    "name": "John",
    "age": 30,
    "cars": {
        "car1": "Ford",
        "car2":: "BMW",
        "car3": "Fiat"
    }
}`
err := json.Unmarshal(j, &m)
if err != nil {
	out, offset := jsonlint.ParseJSONError(j, err)
	fmt.Println(out) // print the error message
	if offset > 0 {
		out = jsonlint.GetErrorJSONSource(j, offset)
		fmt.Println(out) // print the arrow
	}
	return
}

Contributing

  • Fork the repo on GitHub
  • Clone the project to your own machine
  • Create a branch with your modifications git checkout -b fantastic-feature.
  • Then commit your changes git commit -m 'Implementation of new fantastic feature'
  • Make a push to your branch git push origin fantastic-feature.
  • Submit a Pull Request so that we can review your changes