{"id":37146147,"url":"https://github.com/git-lfs/gojsonschema","last_synced_at":"2026-01-14T17:00:53.743Z","repository":{"id":57611426,"uuid":"81590041","full_name":"git-lfs/gojsonschema","owner":"git-lfs","description":"An implementation of JSON Schema, draft v4 - Go language","archived":false,"fork":true,"pushed_at":"2017-02-13T16:31:06.000Z","size":376,"stargazers_count":4,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-20T19:21:10.851Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"xeipuuv/gojsonschema","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/git-lfs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE-2.0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-10T17:39:53.000Z","updated_at":"2024-04-26T11:03:10.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/git-lfs/gojsonschema","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/git-lfs/gojsonschema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-lfs%2Fgojsonschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-lfs%2Fgojsonschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-lfs%2Fgojsonschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-lfs%2Fgojsonschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/git-lfs","download_url":"https://codeload.github.com/git-lfs/gojsonschema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-lfs%2Fgojsonschema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28427181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T16:38:47.836Z","status":"ssl_error","status_checked_at":"2026-01-14T16:34:59.695Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T17:00:46.869Z","updated_at":"2026-01-14T17:00:53.693Z","avatar_url":"https://github.com/git-lfs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/xeipuuv/gojsonschema.svg)](https://travis-ci.org/xeipuuv/gojsonschema)\n\n# gojsonschema\n\n## Description\n\nAn implementation of JSON Schema, based on IETF's draft v4 - Go language\n\nReferences :\n\n* http://json-schema.org\n* http://json-schema.org/latest/json-schema-core.html\n* http://json-schema.org/latest/json-schema-validation.html\n\n## Installation\n\n```\ngo get github.com/xeipuuv/gojsonschema\n```\n\nDependencies :\n* [github.com/xeipuuv/gojsonpointer](https://github.com/xeipuuv/gojsonpointer)\n* [github.com/xeipuuv/gojsonreference](https://github.com/xeipuuv/gojsonreference)\n* [github.com/stretchr/testify/assert](https://github.com/stretchr/testify#assert-package)\n\n## Usage\n\n### Example\n\n```go\n\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/xeipuuv/gojsonschema\"\n)\n\nfunc main() {\n\n    schemaLoader := gojsonschema.NewReferenceLoader(\"file:///home/me/schema.json\")\n    documentLoader := gojsonschema.NewReferenceLoader(\"file:///home/me/document.json\")\n\n    result, err := gojsonschema.Validate(schemaLoader, documentLoader)\n    if err != nil {\n        panic(err.Error())\n    }\n\n    if result.Valid() {\n        fmt.Printf(\"The document is valid\\n\")\n    } else {\n        fmt.Printf(\"The document is not valid. see errors :\\n\")\n        for _, desc := range result.Errors() {\n            fmt.Printf(\"- %s\\n\", desc)\n        }\n    }\n\n}\n\n\n```\n\n#### Loaders\n\nThere are various ways to load your JSON data.\nIn order to load your schemas and documents,\nfirst declare an appropriate loader :\n\n* Web / HTTP, using a reference :\n\n```go\nloader := gojsonschema.NewReferenceLoader(\"http://www.some_host.com/schema.json\")\n```\n\n* Local file, using a reference :\n\n```go\nloader := gojsonschema.NewReferenceLoader(\"file:///home/me/schema.json\")\n```\n\nReferences use the URI scheme, the prefix (file://) and a full path to the file are required.\n\n* JSON strings :\n\n```go\nloader := gojsonschema.NewStringLoader(`{\"type\": \"string\"}`)\n```\n\n* Custom Go types :\n\n```go\nm := map[string]interface{}{\"type\": \"string\"}\nloader := gojsonschema.NewGoLoader(m)\n```\n\nAnd\n\n```go\ntype Root struct {\n\tUsers []User `json:\"users\"`\n}\n\ntype User struct {\n\tName string `json:\"name\"`\n}\n\n...\n\ndata := Root{}\ndata.Users = append(data.Users, User{\"John\"})\ndata.Users = append(data.Users, User{\"Sophia\"})\ndata.Users = append(data.Users, User{\"Bill\"})\n\nloader := gojsonschema.NewGoLoader(data)\n```\n\n#### Validation\n\nOnce the loaders are set, validation is easy :\n\n```go\nresult, err := gojsonschema.Validate(schemaLoader, documentLoader)\n```\n\nAlternatively, you might want to load a schema only once and process to multiple validations :\n\n```go\nschema, err := gojsonschema.NewSchema(schemaLoader)\n...\nresult1, err := schema.Validate(documentLoader1)\n...\nresult2, err := schema.Validate(documentLoader2)\n...\n// etc ...\n```\n\nTo check the result :\n\n```go\n    if result.Valid() {\n    \tfmt.Printf(\"The document is valid\\n\")\n    } else {\n        fmt.Printf(\"The document is not valid. see errors :\\n\")\n        for _, err := range result.Errors() {\n        \t// Err implements the ResultError interface\n            fmt.Printf(\"- %s\\n\", err)\n        }\n    }\n```\n\n## Working with Errors\n\nThe library handles string error codes which you can customize by creating your own gojsonschema.locale and setting it\n```go\ngojsonschema.Locale = YourCustomLocale{}\n```\n\nHowever, each error contains additional contextual information.\n\n**err.Type()**: *string* Returns the \"type\" of error that occurred. Note you can also type check. See below\n\nNote: An error of RequiredType has an err.Type() return value of \"required\"\n\n    \"required\": RequiredError\n    \"invalid_type\": InvalidTypeError\n    \"number_any_of\": NumberAnyOfError\n    \"number_one_of\": NumberOneOfError\n    \"number_all_of\": NumberAllOfError\n    \"number_not\": NumberNotError\n    \"missing_dependency\": MissingDependencyError\n    \"internal\": InternalError\n    \"enum\": EnumError\n    \"array_no_additional_items\": ArrayNoAdditionalItemsError\n    \"array_min_items\": ArrayMinItemsError\n    \"array_max_items\": ArrayMaxItemsError\n    \"unique\": ItemsMustBeUniqueError\n    \"array_min_properties\": ArrayMinPropertiesError\n    \"array_max_properties\": ArrayMaxPropertiesError\n    \"additional_property_not_allowed\": AdditionalPropertyNotAllowedError\n    \"invalid_property_pattern\": InvalidPropertyPatternError\n    \"string_gte\": StringLengthGTEError\n    \"string_lte\": StringLengthLTEError\n    \"pattern\": DoesNotMatchPatternError\n    \"multiple_of\": MultipleOfError\n    \"number_gte\": NumberGTEError\n    \"number_gt\": NumberGTError\n    \"number_lte\": NumberLTEError\n    \"number_lt\": NumberLTError\n\n**err.Value()**: *interface{}* Returns the value given\n\n**err.Context()**: *gojsonschema.jsonContext* Returns the context. This has a String() method that will print something like this: (root).firstName\n\n**err.Field()**: *string* Returns the fieldname in the format firstName, or for embedded properties, person.firstName. This returns the same as the String() method on *err.Context()* but removes the (root). prefix.\n\n**err.Description()**: *string* The error description. This is based on the locale you are using. See the beginning of this section for overwriting the locale with a custom implementation.\n\n**err.Details()**: *gojsonschema.ErrorDetails* Returns a map[string]interface{} of additional error details specific to the error. For example, GTE errors will have a \"min\" value, LTE will have a \"max\" value. See errors.go for a full description of all the error details. Every error always contains a \"field\" key that holds the value of *err.Field()*\n\nNote in most cases, the err.Details() will be used to generate replacement strings in your locales, and not used directly. These strings follow the text/template format i.e.\n```\n{{.field}} must be greater than or equal to {{.min}}\n```\n\n## Formats\nJSON Schema allows for optional \"format\" property to validate strings against well-known formats. gojsonschema ships with all of the formats defined in the spec that you can use like this:\n````json\n{\"type\": \"string\", \"format\": \"email\"}\n````\nAvailable formats: date-time, hostname, email, ipv4, ipv6, uri.\n\nFor repetitive or more complex formats, you can create custom format checkers and add them to gojsonschema like this:\n\n```go\n// Define the format checker\ntype RoleFormatChecker struct {}\n\n// Ensure it meets the gojsonschema.FormatChecker interface\nfunc (f RoleFormatChecker) IsFormat(input string) bool {\n    return strings.HasPrefix(\"ROLE_\", input)\n}\n\n// Add it to the library\ngojsonschema.FormatCheckers.Add(\"role\", RoleFormatChecker{})\n````\n\nNow to use in your json schema:\n````json\n{\"type\": \"string\", \"format\": \"role\"}\n````\n\n## Uses\n\ngojsonschema uses the following test suite :\n\nhttps://github.com/json-schema/JSON-Schema-Test-Suite\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgit-lfs%2Fgojsonschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgit-lfs%2Fgojsonschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgit-lfs%2Fgojsonschema/lists"}