{"id":32270341,"url":"https://github.com/thinkassembly/json_typedef_dart","last_synced_at":"2026-07-11T06:32:14.177Z","repository":{"id":56833386,"uuid":"458653109","full_name":"thinkassembly/json_typedef_dart","owner":"thinkassembly","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-16T22:39:12.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-12T07:08:21.520Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thinkassembly.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-12T22:21:56.000Z","updated_at":"2023-09-13T13:40:50.000Z","dependencies_parsed_at":"2022-09-05T12:51:14.258Z","dependency_job_id":null,"html_url":"https://github.com/thinkassembly/json_typedef_dart","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thinkassembly/json_typedef_dart","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkassembly%2Fjson_typedef_dart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkassembly%2Fjson_typedef_dart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkassembly%2Fjson_typedef_dart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkassembly%2Fjson_typedef_dart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thinkassembly","download_url":"https://codeload.github.com/thinkassembly/json_typedef_dart/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thinkassembly%2Fjson_typedef_dart/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35353668,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-11T02:00:05.354Z","response_time":104,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2025-10-22T22:35:36.621Z","updated_at":"2026-07-11T06:32:14.171Z","avatar_url":"https://github.com/thinkassembly.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jtd: JSON Validation for Dart\n\n\n[JSON Type Definition](https://jsontypedef.com), aka [RFC\n8927](https://tools.ietf.org/html/rfc8927), is an easy-to-learn, standardized\nway to define a schema for JSON data. You can use JSON Typedef to portably\nvalidate data across programming languages, create dummy data, generate code,\nand more.\n\nThis package is a Dart / Flutter implementation of JSON Type\nDefinition. It lets you validate input data against JSON Type Definition\nschemas. \n\n\n\n## Installation\n\nYou can install this package with `pub`\n\n\n## Documentation\n\n\n\nFor more high-level documentation about JSON Typedef in general see:\n\n* [The JSON Typedef Website][jtd]\n\n## Basic Usage\n\nHere's an example of how you can use this package to validate JSON data against\na JSON Typedef schema:\n\n```dart\nimport 'package:json_typedef_dart/json_typedef_dart.dart';\n\nJson schema = \u003cString, dynamic\u003e{\n   \"properties\": {\n      \"name\": {\"type\": \"string\"},\n      \"age\": {\"type\": \"uint32\"},\n      \"phones\": {\n         \"elements\": {\"type\": \"string\"}\n      }\n   }\n};\n\nvoid main() {\n// validate returns an array of validation errors. If there were no problems\n// with the input, it returns an empty array.\n\n// Outputs: []\n   print(validate(schema: schema, data: {\n      \"name\": \"John Doe\",\n              \"age\": 43,\n              \"phones\": [\"+44 1234567\", \"+44 2345678\"],\n   }));\n\n// This next input has three problems with it:\n//\n// 1. It's missing \"name\", which is a required property.\n// 2. \"age\" is a string, but it should be an integer.\n// 3. \"phones[1]\" is a number, but it should be a string.\n//\n// Each of those errors corresponds to one of the errors returned by validate.\n\n// Outputs:\n//\n// [\n//   { instancePath: [], schemaPath: [ 'properties', 'name' ] },\n//   {\n//     instancePath: [ 'age' ],\n//     schemaPath: [ 'properties', 'age', 'type' ]\n//   },\n//   {\n//     instancePath: [ 'phones', '1' ],\n//     schemaPath: [ 'properties', 'phones', 'elements', 'type' ]\n//   }\n// ]\n   print(validate(schema: schema, data: {\n      \"age\": \"43\",\n              \"phones\": [\"+44 1234567\", 442345678],\n   }));\n}\n```\n\n## Advanced Usage: Limiting Errors Returned\n\nBy default, `validate` returns every error it finds. If you just care about\nwhether there are any errors at all, or if you can't show more than some number\nof errors, then you can get better performance out of `validate` using the\n`maxErrors` option.\n\nFor example, taking the same example from before, but limiting it to 1 error, we\nget:\n\n```dart\nimport 'package:json_typedef_dart/json_typedef_dart.dart';\n\nJson schema = \u003cString, dynamic\u003e{\n   \"properties\": {\n      \"name\": {\"type\": \"string\"},\n      \"age\": {\"type\": \"uint32\"},\n      \"phones\": {\n         \"elements\": {\"type\": \"string\"}\n      }\n   }\n};\n\nvoid main() {\n// Outputs:\n//\n// [ { instancePath: [], schemaPath: [ 'properties', 'name' ] } ]\n   print(validate(schema: schema, data: {\n      \"age\": \"43\",\n              \"phones\": [\"+44 1234567\", \"+44 2345678\"],\n   },maxErrors: 1));\n\n}\n```\n\n## Advanced Usage: Handling Untrusted Schemas\n\nIf you want to run `validate` against a schema that you don't trust, then you should:\n\n1. Ensure the schema is well-formed, using  `isValidSchema` which validates things like making sure all `ref`s have\n   corresponding definitions.\n\n2. Call `validate` with the `maxDepth` option. JSON Typedef lets you write\n   recursive schemas -- if you're evaluating against untrusted schemas, you\n   might go into an infinite loop when evaluating against a malicious input,\n   such as this one:\n\n```json\n   {\n     \"ref\": \"loop\",\n     \"definitions\": {\n       \"loop\": {\n         \"ref\": \"loop\"\n       }\n     }\n   }\n```\n\n   The `maxDepth` option tells `jtd.validate` how many `ref`s to follow\n   recursively before giving up and throwing `MaxDepthExceededError`.\n\nHere's an example of how you can use `jtd` to evaluate data against an untrusted\nschema:\n\n```dart\nimport 'package:json_typedef_dart/json_typedef_dart.dart';\n\n// validateUntrusted returns true if `data` satisfies `schema`, and false if it\n// does not. Throws an error if `schema` is invalid, or if validation goes in an\n// infinite loop.\nbool validateUntrusted(Json schema, dynamic data) {\n   if (!isValidSchema(schema)) {\n      throw Exception(\"invalid schema\");\n   }\n\n// You should tune maxDepth to be high enough that most legitimate schemas\n// evaluate without errors, but low enough that an attacker cannot cause a\n// denial of service attack.\n   return validate(schema: schema, data: data, maxDepth: 32).isEmpty;\n}\n\nvoid main() {\n// Outputs: true\n   print(validateUntrusted(\u003cString, dynamic\u003e{\"type\": \"string\"}, \"foo\"));\n\n// Outputs: false\n   validateUntrusted(\u003cString, dynamic\u003e{\"type\": \"string\"}, null);\n\n// Throws \"invalid schema\"\n   try {\n      validateUntrusted(\u003cString, dynamic\u003e{\"type\": \"nonsense\"}, null);\n   } catch (e) {\n      print(e);\n   }\n// Throws an instance of MaxDepthExceededError\n   try {\n      validateUntrusted(\u003cString, dynamic\u003e{\n         \"ref\": \"loop\",\n         \"definitions\": {\n            \"loop\": {\"ref\": \"loop\"}\n         }\n      }, null);\n   }\n   catch(e){\n      print(e);\n   }\n}\n```\n\n[jtd]: https://jsontypedef.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkassembly%2Fjson_typedef_dart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkassembly%2Fjson_typedef_dart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkassembly%2Fjson_typedef_dart/lists"}