{"id":31976746,"url":"https://github.com/arineng/jcrvalidator","last_synced_at":"2025-10-14T21:15:12.043Z","repository":{"id":55393892,"uuid":"42195612","full_name":"arineng/jcrvalidator","owner":"arineng","description":"JSON Content Rules Validator","archived":false,"fork":false,"pushed_at":"2021-01-03T14:08:24.000Z","size":751,"stargazers_count":3,"open_issues_count":16,"forks_count":5,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-10-09T13:55:29.840Z","etag":null,"topics":["jcr","json"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arineng.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":"2015-09-09T18:07:22.000Z","updated_at":"2024-09-11T08:19:14.000Z","dependencies_parsed_at":"2022-08-14T23:20:19.800Z","dependency_job_id":null,"html_url":"https://github.com/arineng/jcrvalidator","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/arineng/jcrvalidator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arineng%2Fjcrvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arineng%2Fjcrvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arineng%2Fjcrvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arineng%2Fjcrvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arineng","download_url":"https://codeload.github.com/arineng/jcrvalidator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arineng%2Fjcrvalidator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015933,"owners_count":26085777,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"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":["jcr","json"],"created_at":"2025-10-14T21:15:10.748Z","updated_at":"2025-10-14T21:15:12.030Z","avatar_url":"https://github.com/arineng.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Content Rules Validator\n\n[![Gem Version](https://badge.fury.io/rb/jcrvalidator.svg)](https://badge.fury.io/rb/jcrvalidator)\n[![Build Status](https://travis-ci.org/arineng/jcrvalidator.svg)](https://travis-ci.org/arineng/jcrvalidator)\n[![Build status](https://ci.appveyor.com/api/projects/status/h4vyvejioaqwcs4u?svg=true)](https://ci.appveyor.com/project/anewton1998/jcrvalidator)\n[![Dependency Status](https://gemnasium.com/badges/github.com/arineng/jcrvalidator.svg)](https://gemnasium.com/github.com/arineng/jcrvalidator)\n[![Coverage Status](https://coveralls.io/repos/github/arineng/jcrvalidator/badge.svg?branch=master)](https://coveralls.io/github/arineng/jcrvalidator?branch=master)\n\n## Background\n\nJSON Content Rules (JCR) is a language for specifying and testing the interchange of data in JSON \nformat used by computer protocols and processes.  The syntax of JCR is a superset of JSON\npossessing the conciseness and utility that has made JSON popular. It was created by the \nAmerican Registry for Internet Numbers (ARIN) in an effort to better describe the JSON structures \nin protocols such as RDAP.\n\n### A First Example: Specifying Content\n\n   The following JSON data describes a JSON object with two members,\n   \"line-count\" and \"word-count\", each containing an integer.\n\n      { \"line-count\" : 3426, \"word-count\" : 27886 }\n\n   This is also JCR that describes a JSON object with a member named\n   \"line-count\" that is an integer that is exactly 3426 and a member\n   named \"word-count\" that is an integer that is exactly 27886.\n\n   For a protocol specification, it is probably more useful to specify\n   that each member is any integer and not specific, exact integers:\n\n      { \"line-count\" : integer, \"word-count\" : integer }\n\n   Since line counts and word counts should be either zero or a positive\n   integer, the specification may be further narrowed:\n\n      { \"line-count\" : 0.. , \"word-count\" : 0.. }\n      \n### A Second Example: Testing Content\n\n   Building on the first example, this second example describes the same\n   object but with the addition of another member, \"file-name\".\n\n      {\n        \"file-name\"  : \"rfc7159.txt\",\n        \"line-count\" : 3426,\n        \"word-count\" : 27886\n      }\n\n   The following JCR describes objects like it.\n\n      {\n        \"file-name\"  : string,\n        \"line-count\" : 0..,\n        \"word-count\" : 0..\n      }\n\n\n   For the purposes of writing a protocol specification, JCR may be\n   broken down into named rules to reduce complexity and to enable re-use.  The following example takes the JCR from above and rewrites the\n   members as named rules.\n\n      {\n        $fn,\n        $lc,\n        $wc\n      }\n\n      $fn = \"file-name\"  : string\n      $lc = \"line-count\" : 0..\n      $wc = \"word-count\" : 0..\n\n   With each member specified as a named rule, software testers can\n   override them locally for specific test cases.  In the following\n   example, the named rules are locally overridden for the test case\n   where the file name is \"rfc4627.txt\".\n\n      $fn = \"file-name\"  : \"rfc4627.txt\"\n      $lc = \"line-count\" : 2102\n      $wc = \"word-count\" : 16714\n\n   In this example, the protocol specification describes the JSON object\n   in general and an implementation overrides the rules for testing\n   specific cases.\n   \n### More Information on JCR\n\nMore information on JCR can be found at [json-content-rules.org](http://json-content-rules.org/). \nThe current published specification is an IETF Internet Draft (I-D) versioned as -09,\nThis software closely tracks the -09 version, \nwhich can be found [here](https://raw.githubusercontent.com/arineng/jcr/09/draft-newton-json-content-rules-09.txt)\n   \n## Version History\n\nThe version history can be seen in the [CHANGE LOG](https://github.com/arineng/jcrvalidator/wiki/CHANGELOG)\non the project wiki.\n\nThe current version of the JCR specification can be found \n[here](https://raw.githubusercontent.com/arineng/jcr/07/draft-newton-json-content-rules.txt)\n  \n## Features\n\nThis JCR Validator can be used by other Ruby code directly, \nor it may be invoked on the command line using the `jcr` command.\n\nThe command line utility can be given specific override rulesets for \nthe purposes of local testing. If no root rule is given, it will test against all roots.\n\nThe library has all the features of the command line utility, \nand also has the ability to allow for custom validation of rules using Ruby code.\n  \n## Installation\n\nTo install the JCR Validator:\n\n```\ngem install jcrvalidator\n```\n\nThis code was written and tested on Ruby 2.1, 2.3, and 2.4. \n\n## Command Line Usage\n\nYou can find a bunch of command line examples in `examples/examples.sh`\n\nHere are some quick nibbles:\n\n```\n$ echo \"[ 1, 2]\" | bin/jcr -v -R \"[ integer * ]\"\nSuccess!\n\n$ echo \"[ 1, 2]\" | bin/jcr -v -R \"[ string * ]\"\nFailure: ....\n\n$ bin/jcr -v -r example.jcr example.json\nSuccess!\n\n$ bin/jcr -h\nHELP\n----\n\nUsage: jcr [OPTIONS] [JSON_FILES]\n\nEvaluates JSON against JSON Content Rules (JCR).\n\nIf -J is not specified, JSON_FILES is used.\nIf JSON_FILES is not specified, standard input (STDIN) is used.\n\nUse -v to see results, otherwise check the exit code.\n\nOptions\n    -r FILE                          file containing ruleset\n    -R STRING                        string containing ruleset. Should probably be quoted\n        --test-jcr                   parse and test the JCR only\n        --process-parts [DIRECTORY]  creates smaller files for specification writing\n    -S STRING                        name of root rule. All roots will be tried if none is specified\n    -o FILE                          file containing overide ruleset (option can be repeated)\n    -O STRING                        string containing overide rule (option can be repeated)\n    -J STRING                        string containing JSON to evaluate. Should probably be quoted\n    -v                               verbose\n    -q                               quiet\n    -h                               display help\n\nReturn codes:\n 0 = success\n 1 = bad JCR parsing or other bad condition\n 2 = invalid option or bad use of command\n 3 = unsuccessful evaluation of JSON\n\nJCR Version 0.8.1\n```\n\n## Usage as a Library\n\nIt is easy to call the JCR Validator from Ruby programs. The `examples` directory contains some good examples:\n\n* `simple.rb` is a simple and basic example\n* `override.rb` shows how to override specific rules in a ruleset.\n* `callback.rb` demonstrates how to do custom validation with callbacks\n* `trace_failures.rb` demonstrates how to access validation failure information\n\n### Custom Validation Using Callbacks\n\nThe `callback.rb` demonstrates the usage of custom code for evaluation of rules. There are a few important things to note about how callbacks work:\n\n1. The validator will first evaluate a rule with internal validation before calling the callback code. This means child rules are evaluated by the validators own internal logic before a callback is invoked, and also that a callback for a child rule is called before the callback for its parent.\n2. Depending on the internal evaluation, the callback is either invoked at the `rule_eval_true` or `rule_eval_false` methods.\n3. The callback can return a `JCR::Evaluation` object to signify if the evaluation passed or not.\n4. If the callback simply returns true, this is turned into a `JCR::Evaluation` signifying a passed evaluation.\n5. If the callback returns false or a string, this is turned into a `JCR::Evaluation` signifying a failed evaluation. In cases where a string is returned, the string is used as the reason for failing the evaluation.\n6. For validation of rules inside arrays and objects, a failed evaluation will usually result in the terminating the evaluation of the rest of the sibling rules of the containing array or object.\n\n## Using the `--process-parts` Option\n\nThe `--process-parts` option extracts parts of a JCR file into multiple files based\non comments in the file. It can also create a new file without the\ncomments. This is useful for rulesets going into specification documents\nwhere it is nice to break the rulesets up for illustrative purposes in\nthe specification but to also have one JCR file for programmatic\ntesting purposes.\n\nThe file parts are extracted using the comments\n\n    ; start_part FILENAME\n    \nand\n\n    ; end_part\n    \nThe comments must also be the only thing present on the line\nthough leading whitespace is allowed if desired.\n\nTo get a new file with all parts but these comments, use this\n\n    ; all_parts FILENAME\n    \nThe `--process-parts` parameter will also take an optional directory name where it\nwill write the files.\n\n## Building\n\nUse bundler to install all the dependencies.\n\nIf you do not have bundler, it is simple to install:\n\n```\n$ gem install bundler\n```\n\nFrom there, tell bundler to go get the rest of the gems:\n\n```\n$ bundle install\n```\n\nTo run the unit tests on Linux or Unix-like OS (including Windows Subsystem for Linux):\n\n```\n$ bundle exec rake test\n````\nTo run the unit tests on native Windows (Ruby installed via RubyInstaller):\n\n```\n$ bundle exec rake win_test\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farineng%2Fjcrvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farineng%2Fjcrvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farineng%2Fjcrvalidator/lists"}