{"id":24652322,"url":"https://github.com/kawasima/json-spec","last_synced_at":"2025-10-07T11:31:32.237Z","repository":{"id":37683249,"uuid":"147442902","full_name":"kawasima/json-spec","owner":"kawasima","description":" JSON Spec is a tool for validation and generation of JSON data. ","archived":false,"fork":false,"pushed_at":"2023-01-07T06:06:16.000Z","size":4588,"stargazers_count":26,"open_issues_count":85,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-20T09:39:58.292Z","etag":null,"topics":["json","json-generator","json-validation"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kawasima.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-09-05T01:38:13.000Z","updated_at":"2024-06-15T11:18:24.000Z","dependencies_parsed_at":"2023-02-06T13:31:11.197Z","dependency_job_id":null,"html_url":"https://github.com/kawasima/json-spec","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawasima%2Fjson-spec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawasima%2Fjson-spec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawasima%2Fjson-spec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kawasima%2Fjson-spec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kawasima","download_url":"https://codeload.github.com/kawasima/json-spec/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235621521,"owners_count":19019522,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["json","json-generator","json-validation"],"created_at":"2025-01-25T19:15:04.971Z","updated_at":"2025-10-07T11:31:31.658Z","avatar_url":"https://github.com/kawasima.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"JSON Spec\n===========\n\nJSON Spec is a tool for validation and generation of JSON data. This is a porting of a part of clojure.spec.\n\n## Validate\n\nSpec is defined as follows\n\n```javascript\nconst s = require('@json-spec/core');\nconst bigEven = s.and(x =\u003e !isNaN(Number(x)), x =\u003e x%2 === 0, x =\u003e x \u003e 1000);\n```\n\nAnd you can validate using the spec\n\n```javascript\ns.isValid(bigEven, 'foo'); // false\ns.isValid(bigEven, 10); // false\ns.isValid(bigEven, 10000); // true\n```\n\nThe example of validating a JSON Object is as follows.\n\n```javascript\nconst isString = x =\u003e typeof(x) === 'string';\nconst emailMatch = x =\u003e new RegExp(/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,63}$/).test(x);\nconst emailType = s.and(isString, emailMatch);\n\nconst person = s.object({\n  first_name: isString,\n  last_name:  isString,\n  email: emailType\n});\n\ns.isValid(person, {\n  first_name: 'Yoshitaka',\n  last_name:  'Kawashima',\n  email: 'kawasima@example.com'\n}); // true\n\n```\n\n## Generate\n\nJSON spec can also generate JSON data that satisfies the defined specification.\n\n```javascript\nconst s = require('@json-spec/core');\nconst gen = require('@json-spec/core/gen');\nconst sp = require('@json-spec/spec-profiles');\nconst sb = require('@json-spec/spec-basic');\n\nconst person = s.object({\n  required: {\n    firstName: sp.name({ size: 100 }),\n    lastName:  sp.name({ size: 100 }),\n    birthDay:  sp.birthDay,\n    postalCd:  sp.postalCode_JP,\n    languages: s.array([\n      \"C\", \"C++\", \"Java\"\n    ])\n  }\n});\n\ngen.sample(s.gen(person))\n```\n\nThis code generates JSON data as follows.\n\n```javascript\n  { firstName: 'n6lB',\n    lastName: 'lvf',\n    birthDay: 1960-05-10T15:00:00.000Z,\n    postalCd: '4874565',\n    languages: [ 'C', 'C', 'C' ] },\n  { firstName: '6',\n    lastName: 'j',\n    birthDay: 2014-11-14T15:00:00.000Z,\n    postalCd: '5244670',\n    languages: [ 'C', 'Java', 'C', 'C++', 'C++' ] },\n  { firstName: '5RV',\n    lastName: 'swy',\n    birthDay: 1989-07-13T15:00:00.000Z,\n    postalCd: '6731807',\n    languages: [ 'C++', 'Java' ] },\n  { firstName: 'ubiIf',\n    lastName: 't5I',\n    birthDay: 1998-11-29T15:00:00.000Z,\n    postalCd: '2768511',\n    languages: [ 'C++', 'C', 'Java', 'C++', 'C', 'C', 'Java' ] },\n  { firstName: 'P',\n    lastName: '0335Nlbl',\n    birthDay: 2005-08-24T15:00:00.000Z,\n    postalCd: '6810354',\n    languages: [ 'C++', 'C++', 'Java', 'C', 'Java' ] },\n  { firstName: '5uYLGk9j',\n    lastName: 'N',\n    birthDay: 1932-06-06T15:00:00.000Z,\n    postalCd: '2292116',\n    languages: [ 'Java', 'C++', 'Java', 'C', 'C++' ] }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkawasima%2Fjson-spec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkawasima%2Fjson-spec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkawasima%2Fjson-spec/lists"}