Skip to content

10p-freddo/jsonschema-go

 
 

Repository files navigation

JSON Schema structures for Go

Build Status Coverage Status GoDevDoc time tracker Code lines Comments

This library provides Go structures to marshal/unmarshal and reflect JSON Schema documents.

Reflector

Documentation.

type MyStruct struct {
    Amount float64 `json:"amount" minimum:"10.5" example:"20.6" required:"true"`
    Abc    string  `json:"abc" pattern:"[abc]"`
}

reflector := jsonschema.Reflector{}

schema, err := reflector.Reflect(MyStruct{})
if err != nil {
    log.Fatal(err)
}

j, err := json.MarshalIndent(schema, "", " ")
if err != nil {
    log.Fatal(err)
}

fmt.Println(string(j))

// Output:
// {
//  "required": [
//   "amount"
//  ],
//  "properties": {
//   "abc": {
//    "pattern": "[abc]",
//    "type": "string"
//   },
//   "amount": {
//    "examples": [
//     20.6
//    ],
//    "minimum": 10.5,
//    "type": "number"
//   }
//  },
//  "type": "object"
// }

About

JSON Schema mapping for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.3%
  • Makefile 1.7%