https://github.com/golopot/vv
A JSON validation library.
https://github.com/golopot/vv
go json validation
Last synced: 6 months ago
JSON representation
A JSON validation library.
- Host: GitHub
- URL: https://github.com/golopot/vv
- Owner: golopot
- License: mit
- Created: 2020-05-18T08:49:10.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-04T08:25:20.000Z (over 5 years ago)
- Last Synced: 2025-01-18T02:54:28.194Z (over 1 year ago)
- Topics: go, json, validation
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VV
[](https://pkg.go.dev/github.com/golopot/vv)
A json validation library.
- Get json value and validate json at the same time.
- Concise usage.
- Practical error handling.
- Customizable error message.
## Features
- Optional fields and default value
- Disallow extra object fields
- User defined validators
- Customizable error message
## Example
```go
package main
import (
"fmt"
"github.com/golopot/vv"
)
func main() {
v := vv.New([]byte(`
{
"a": 1,
"b": "sss"
}
`))
a := v.Int("a").Done()
z := v.String("z").Default("some-string").Done() // `z` is optional
wrong := v.Int("wrong").Done() // fails validation
fmt.Println(a, z, wrong) // 1 "some-string" 0
// v.ValidationError() stores the first error occured
if err := v.ValidationError(); err != nil {
fmt.Println("error:", err)
// error: property `wrong` should be int
return
}
}
```
## License
MIT