Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aacebo/jsonschema
a zero dependency jsonschema implementation
https://github.com/aacebo/jsonschema
Last synced: about 2 months ago
JSON representation
a zero dependency jsonschema implementation
- Host: GitHub
- URL: https://github.com/aacebo/jsonschema
- Owner: aacebo
- License: mit
- Created: 2024-03-10T06:39:34.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-04-02T20:33:16.000Z (9 months ago)
- Last Synced: 2024-10-20T06:17:06.272Z (2 months ago)
- Language: Go
- Size: 2.08 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonschema
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Go Reference](https://pkg.go.dev/badge/github.com/aacebo/jsonschema.svg)](https://pkg.go.dev/github.com/aacebo/jsonschema)
[![Go Report Card](https://goreportcard.com/badge/github.com/aacebo/jsonschema)](https://goreportcard.com/report/github.com/aacebo/jsonschema)
[![Build Status](https://github.com/aacebo/jsonschema/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/aacebo/jsonschema/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/aacebo/jsonschema/graph/badge.svg?token=ZFJMM1BZVM)](https://codecov.io/gh/aacebo/jsonschema)a zero dependency jsonschema implementation
## Usage
### CLI
```bash
$: jsonschema **/*
```### Files
```go
schema, err := jsonschema.Read("./schema.json")if err != nil {
panic(err)
}errs := jsonschema.Compile(schema)
if len(errs) > 0 {
panic(errs)
}
```### Builder
```go
schema := jsonschema.Builder().
Object().
Properties(map[string]jsonschema.Schema{
"test": jsonschema.Builder().String().Build(),
}).
AdditionalProperties(jsonschema.Builder().Integer().Build()).
Required("test").
Build()errs := jsonschema.Compile(schema)
if len(errs) > 0 {
panic(errs)
}errs = jsonschema.Validate(schema, struct {
Test string `json:"test"`
Other int `json:"other"`
}{"test", 1})if len(errs) > 0 {
panic(errs)
}
```### Non-Global Namespace
```go
namespace := jsonschema.New()
```### Custom Keywords
```go
jsonschema.AddKeyword("alphaNum", jsonschema.Keyword{ ... })
```### Custom Formats
```go
jsonschema.AddFormat("lowercase", func(input string) error {
if strings.ToLower(input) != input {
return errors.New("must be lowercase")
}return nil
})
```## Formats
- date-time
- ipv4
- ipv6
- uri
- uuid## Supported Drafts
| Draft | Status |
|---------|---------|
| 4 | ✅ |
| 6 | ✅ |
| 7 | ✅ |
| 2019-09 | ⏳ |
| 2020-12 | ⏳ |## Features
| Name | Status |
|-----------------------|-----------|
| Custom Keywords | ✅ |
| Custom Error Messages | ⏳ |
| Custom Formats | ✅ |## To Do
- schema builder pattern
- cli
- struct tags
- add message keyword for custom error messages
- keywords:
- object
- unevaluatedProperties
- array
- prefixItems
- unevaluatedItems
- minContains
- maxContains
- deprecated
- readOnly
- writeOnly
- examples
- contentMediaType
- contentEncoding
- if/then/else