{"id":23060097,"url":"https://github.com/rodrigosetti/json-archetype","last_synced_at":"2026-05-01T14:33:20.682Z","repository":{"id":11241247,"uuid":"13637022","full_name":"rodrigosetti/json-archetype","owner":"rodrigosetti","description":"A tool to help testing JSONs","archived":false,"fork":false,"pushed_at":"2014-09-05T18:37:49.000Z","size":280,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-03T07:15:14.035Z","etag":null,"topics":["archetype","json","json-archetype","test-json"],"latest_commit_sha":null,"homepage":null,"language":"Haskell","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/rodrigosetti.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":"2013-10-17T02:24:44.000Z","updated_at":"2020-01-20T03:06:19.000Z","dependencies_parsed_at":"2022-09-14T21:20:19.164Z","dependency_job_id":null,"html_url":"https://github.com/rodrigosetti/json-archetype","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rodrigosetti/json-archetype","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigosetti%2Fjson-archetype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigosetti%2Fjson-archetype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigosetti%2Fjson-archetype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigosetti%2Fjson-archetype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rodrigosetti","download_url":"https://codeload.github.com/rodrigosetti/json-archetype/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigosetti%2Fjson-archetype/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32501401,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"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":["archetype","json","json-archetype","test-json"],"created_at":"2024-12-16T03:11:26.666Z","updated_at":"2026-05-01T14:33:20.661Z","avatar_url":"https://github.com/rodrigosetti.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Archetype [![Build Status](https://travis-ci.org/rodrigosetti/json-archetype.svg?branch=master)](https://travis-ci.org/rodrigosetti/json-archetype)\n\nJSON Archetype is a language designed for testing JSON documents. It validates\nan expected archetype agains one or more JSON documents.\n\nThis project can be thought of a \"XSD\" or \"DTD\" for JSON.\n\n## Motivation\n\nIn several test scenarios (specially in API testing) one desires to compare the\n\"expected\" JSON with the \"actual\" output from the code. By comparing the two\nJSON structures the test can tell if they differ or not, but it's a rigid\napproach since - without a supporting testing code - one cannot allow sensible\nvariations in the actual JSON (such as values that we don't care, arrays that\ncan have a varying number of elements, _etc._)\n\nThis language allows the definition of an \"archetype\", which is a JSON with the\naddition of generic invariant specifications, such as quantity qualifiers,\nregular expressions and type (not value) constrains.\n\nPlease read the example to have a sense of how this works.\n\n## Example\n\nTake, for instance, the following JSON archetype:\n\n````javascript\n/**\n * JSON archetype language is a superset of JSON, and can accept C-style\n * comments (block or line) to help documenting your test.\n */\n\n/* one can assign values to names, and use them later to reuse parts.\n   This is also an example of a non-trivial use of a regular expression\n   to validate an IP address. */\nip_address =  \"[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\\\\.[0-9]{1,3}\"\nserver = { \"ip\": ip_address,\n           \"port\": 8080,\n           \"protocol\": \"http\"}\n\n{\n    \"name\": string,\n    \"version\" ?: 2,          // this key is optional (?)\n    \"data(-.*)?\" *: object,  // this key is a regular expression, and may\n                             // appear zero or more times\n    \"is_member\"   : boolean, // true or false (type restriction)\n    \"is_active\"   : true,    // only true (value restriction)\n    \"coordinates\" : [\"geo\", number{3}], // any array with \"geo\" and 3 numbers\n    \"stream\": [number*],     // a stream is an array of zero or more numbers\n\n    // reusing pre-defined structures. This key should appear three times:\n    \"[a-z]+_server\" {3}: server,\n\n    \"state\" : [string{2,3}, number+], // 2-3 strings and one or more numbers\n\n    \"extra\": any // accepts any value here. the key \"extra\" must exist.\n}\n````\n\nIt defines a structure a JSON must have in order to be valid. The values can be\nvalidated against an exact value (_e.g._ \"http\"), or with a type constrain such\nas `string` or `number`, or even regular expressions (in string literals or\nobject key identifiers). Actually every string and key matching is a regular\nexpression matching, so please be mindful of special characters and proper\nescaping.\n\nFor the given archetype, the following JSON is an example of a valid one (note\nthat order matters in arrays, but it doesn't in objects):\n\n````json\n{\n    \"version\"    : 2,\n    \"is_member\"  : false,\n    \"name\"       : \"John Smith\",\n    \"is_active\"  : true,\n    \"stream\"     : [7, 7, 7, 10, 22, 12, 2, 8],\n    \"coordinates\": [\"geo\", 3123, 133, 319],\n\n    \"dev_server\"   : {\"ip\": \"127.0.0.1\",   \"port\": 8080, \"protocol\": \"http\"},\n    \"stage_server\" : {\"ip\": \"200.6.5.1\",   \"port\": 8080, \"protocol\": \"http\"},\n    \"prod_server\"  : {\"ip\": \"192.178.1.1\", \"port\": 8080, \"protocol\": \"http\"},\n\n    \"data-color\": {\"red\": 10, \"green\": 20, \"blue\": 6},\n    \"data-font\" : {\"family\": \"Lucida\", \"size\": 10, \"unit\": \"pt\"},\n\n    \"extra\": {\"foo\": \"bar\",\n              \"bar\": null},\n    \"state\": [\"spam\", \"eggs\", 1, 2, 3]\n}\n````\n\n## Syntax\n\nOn top of normal JSON syntax, one can use \"type qualifiers\", anywhere a JSON\nvalue could be, to identify that a value must be of a specific type: `object`,\n`list`, `string`, `number`, `boolean`, or `any` (`null` is a type and a value\nitself).\n\nQuantity qualifiers can be optionally used right after array values and object\nkey literals to specify that the given array value or object key/value pair\nshould occur a certain number of times. They have the same syntax as their\nPOSIX regular expressions counterparts: `?` (optional), `*` (zero or more), `+`\n(one or more), `{n}` (n repetitions), or `{n,m}` (n to m repetitions).\n\n## Installation and usage\n\nTo compile and install, please first install [Haskell](http://www.haskell.org)\nfor your platform.\n\nFollowing that, run `cabal install` ([Cabal](http://www.haskell.org/cabal/) is\nHaskell package manager, see `cabal help` for other options) to compile and\ninstall the binary.\n\nFinally, you can run the validator:\n\n```console\n json-test \u003coptions\u003e [file [file ...]]\n   -h           --help                Display help information\n                --version             Display program version\n   -a FILENAME  --archetype=FILENAME  The JSON archetype file name\n```\n\nIf no JSON filename is given, then reads from standard input.\n\nThis project uses [Semantic Versioning](http://semver.org), so any major\nversion number changes means that the previous version's archetypes may be\nincompatible with the new syntax (this change shouldn't happen in practice).\n\n## Development\n\nFor development, I recommend using `cabal sandbox` (see `cabal help sandbox`\nfor details) to create a dependency environment (_i.e._ virtual environment) to\ninstall the dependencies and test, _e.g._, after cloning the project:\n\n```console\n$ cabal sandbox init\n$ cabal install --dependencies-only\n$ ./run-tests.sh\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigosetti%2Fjson-archetype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodrigosetti%2Fjson-archetype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigosetti%2Fjson-archetype/lists"}