https://github.com/aren55555/jsonapivalidator
A go library for validating the JSON API specification (http://jsonapi.org/format/)
https://github.com/aren55555/jsonapivalidator
golang-library jsonapi
Last synced: 14 days ago
JSON representation
A go library for validating the JSON API specification (http://jsonapi.org/format/)
- Host: GitHub
- URL: https://github.com/aren55555/jsonapivalidator
- Owner: aren55555
- License: mit
- Created: 2016-07-20T05:38:06.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-07T03:19:28.000Z (over 8 years ago)
- Last Synced: 2025-12-16T03:17:47.997Z (about 1 month ago)
- Topics: golang-library, jsonapi
- Language: Go
- Homepage:
- Size: 49.8 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonapivalidator [](https://travis-ci.org/aren55555/jsonapivalidator) [](http://godoc.org/github.com/aren55555/jsonapivalidator)
A validator that determines whether arbitrary JSON payloads are in compliance with the [JSON API specification](http://jsonapi.org/). If the JSON is not compliant this validator will indicate the reason why.
This validator has been written in [Go](https://golang.org/), but it is easy to use it in a Javascript environment thanks to [GopherJS](https://gopherjs.github.io/); see [github.com/aren55555/corroborate](https://github.com/aren55555/corroborate) for a working JS implementation.
## Installation
```
go get -u github.com/aren55555/jsonapivalidator
```
## Examples
### Valid JSON API Payload
```go
req, err := http.DefaultClient.Get("https://raw.githubusercontent.com/aren55555/jsonapivalidator/master/test/samples/valid/default.json")
result, err := jsonapivalidator.UnmarshalAndValidate(req.Body)
if err != nil {
panic(err)
}
if result.IsValid() {
fmt.Println("The JSON sample was valid!")
}
```
### Invalid JSON API Payload
```go
req, err = http.DefaultClient.Get("https://raw.githubusercontent.com/aren55555/jsonapivalidator/master/test/samples/invalid/default.json")
result, err = jsonapivalidator.UnmarshalAndValidate(req.Body)
if err != nil {
panic(err)
}
fmt.Println("Errors:")
for i, err := range result.Errors() {
fmt.Println("\t", i, err)
}
fmt.Println("Warnings:")
for i, err := range result.Warnings() {
fmt.Println("\t", i, err)
}
```