A tool to generate Go data types from JSON Schema definitions.
803
stars
607
commits
Go
primary language
Sep 6, 2026
updated
go-jsonschema is a tool to generate Go data types from JSON Schema definitions.
This tool generates Go data types and structs that corresponds to definitions in the schema, along with unmarshalling code that validates the input JSON according to the schema's validation rules.
Download: Get a release here.
Install from source: To install with Go 1.25+:
go get github.com/atombender/go-jsonschema/...
go install github.com/atombender/go-jsonschema@latest
brew tap omissis/go-jsonschema
brew install go-jsonschema
This project makes use of go workspaces in order to ease testing of the generated code during development while keeping the codebase as tidy and maintainable as possible. It's an unusual choice, but it allows to not only test the code-generation logic, but also the generated code itself.
At its most basic:
go-jsonschema -p main schema.json
This will write a Go source file to standard output, declared under the package main.
You can generate code for multiple schemas in one run, optionally writing to different files inside different packages:
$ go-jsonschema \
--schema-package=https://example.com/schema1=github.com/myuser/myproject \
--schema-output=https://example.com/schema1=schema1.go \
--schema-package=https://example.com/schema2=github.com/myuser/myproject/stuff \
--schema-output=https://example.com/schema2=stuff/schema2.go \
schema1.json schema2.json
This will create schema1.go (declared as package myproject) and stuff/schema2.go (declared as package stuff).
If schema1.json refers to schema2.json or viceversa, the two Go files will import the other depended-on package.
Note the flag format:
--schema-package=https://example.com/schema1=github.com/myuser/myproject \
^ ^
| |
schema $id full import URL
It sometimes happen that new features or bug fixes to the library require regenerating the tests' golden files, here's how to do it:
export OVERWRITE_EXPECTED_GO_FILE="true"
make test
In a few cases, special types are used to help with serializing/deserializing data frrom JSON. Namely a custom types is provided for the following semantic types:
SerializableDateSerializableTimeThese types are needed because there is no native type provided by Go which properly handles them.
While not finished, go-jsonschema can be used today. Aside from some minor features, only specific validations remain to be fully implemented.
nullbooleanobjectarraynumber
json.Numberstring#/$defs/someName#/$defs/someName/$defs/someOtherNamemyschema.json#/$defs/someNamemyschema.json#/$defs/someName/$defs/someOtherNamedescriptiondefault (only for struct fields)readOnlywriteOnlytitleexamplesenumtype (single)type (multiple; note: partial support, limited validation)constmultipleOfmaximumexclusiveMaximumminimumexclusiveMinimummaxLengthminLengthpatternitemsmaxItemsminItemsuniqueItemsadditionalItemscontainsrequiredpropertiespatternPropertiesdependenciespropertyNamesmaxPropertiesminPropertiesifthenelseallOfanyOfoneOfnotMIT license. See LICENSE file.
(top 30 of 52)
Go
93.1%
Makefile
3.7%
Shell
3.0%
A tool to generate Go data types from JSON Schema definitions.
803
stars
607
commits
Go
primary language
Sep 6, 2026
updated
go-jsonschema is a tool to generate Go data types from JSON Schema definitions.
This tool generates Go data types and structs that corresponds to definitions in the schema, along with unmarshalling code that validates the input JSON according to the schema's validation rules.
Download: Get a release here.
Install from source: To install with Go 1.25+:
go get github.com/atombender/go-jsonschema/...
go install github.com/atombender/go-jsonschema@latest
brew tap omissis/go-jsonschema
brew install go-jsonschema
This project makes use of go workspaces in order to ease testing of the generated code during development while keeping the codebase as tidy and maintainable as possible. It's an unusual choice, but it allows to not only test the code-generation logic, but also the generated code itself.
At its most basic:
go-jsonschema -p main schema.json
This will write a Go source file to standard output, declared under the package main.
You can generate code for multiple schemas in one run, optionally writing to different files inside different packages:
$ go-jsonschema \
--schema-package=https://example.com/schema1=github.com/myuser/myproject \
--schema-output=https://example.com/schema1=schema1.go \
--schema-package=https://example.com/schema2=github.com/myuser/myproject/stuff \
--schema-output=https://example.com/schema2=stuff/schema2.go \
schema1.json schema2.json
This will create schema1.go (declared as package myproject) and stuff/schema2.go (declared as package stuff).
If schema1.json refers to schema2.json or viceversa, the two Go files will import the other depended-on package.
Note the flag format:
--schema-package=https://example.com/schema1=github.com/myuser/myproject \
^ ^
| |
schema $id full import URL
It sometimes happen that new features or bug fixes to the library require regenerating the tests' golden files, here's how to do it:
export OVERWRITE_EXPECTED_GO_FILE="true"
make test
In a few cases, special types are used to help with serializing/deserializing data frrom JSON. Namely a custom types is provided for the following semantic types:
SerializableDateSerializableTimeThese types are needed because there is no native type provided by Go which properly handles them.
While not finished, go-jsonschema can be used today. Aside from some minor features, only specific validations remain to be fully implemented.
nullbooleanobjectarraynumber
json.Numberstring#/$defs/someName#/$defs/someName/$defs/someOtherNamemyschema.json#/$defs/someNamemyschema.json#/$defs/someName/$defs/someOtherNamedescriptiondefault (only for struct fields)readOnlywriteOnlytitleexamplesenumtype (single)type (multiple; note: partial support, limited validation)constmultipleOfmaximumexclusiveMaximumminimumexclusiveMinimummaxLengthminLengthpatternitemsmaxItemsminItemsuniqueItemsadditionalItemscontainsrequiredpropertiespatternPropertiesdependenciespropertyNamesmaxPropertiesminPropertiesifthenelseallOfanyOfoneOfnotMIT license. See LICENSE file.
(top 30 of 52)
Go
93.1%
Makefile
3.7%
Shell
3.0%