{"id":15386640,"url":"https://github.com/christianmurphy/json-schema-keyref","last_synced_at":"2025-06-30T00:34:04.542Z","repository":{"id":37269941,"uuid":"63826565","full_name":"ChristianMurphy/json-schema-keyref","owner":"ChristianMurphy","description":"Validate key references from JSON Schema","archived":false,"fork":false,"pushed_at":"2025-06-25T12:41:33.000Z","size":3303,"stargazers_count":2,"open_issues_count":17,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-25T13:43:39.285Z","etag":null,"topics":["json-schema","key-value","typescript"],"latest_commit_sha":null,"homepage":"https://christianmurphy.github.io/json-schema-keyref","language":"TypeScript","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/ChristianMurphy.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-07-21T01:27:06.000Z","updated_at":"2024-07-09T12:03:23.000Z","dependencies_parsed_at":"2023-09-26T01:53:40.713Z","dependency_job_id":"b421d900-556f-48c2-b8f8-1dfe980f512d","html_url":"https://github.com/ChristianMurphy/json-schema-keyref","commit_stats":{"total_commits":1025,"total_committers":5,"mean_commits":205.0,"dds":"0.32780487804878045","last_synced_commit":"9e82b600e75d1f6abaa3eb09ef8bedf386c1527e"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/ChristianMurphy/json-schema-keyref","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianMurphy%2Fjson-schema-keyref","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianMurphy%2Fjson-schema-keyref/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianMurphy%2Fjson-schema-keyref/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianMurphy%2Fjson-schema-keyref/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChristianMurphy","download_url":"https://codeload.github.com/ChristianMurphy/json-schema-keyref/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChristianMurphy%2Fjson-schema-keyref/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262689724,"owners_count":23349136,"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-schema","key-value","typescript"],"created_at":"2024-10-01T14:50:01.823Z","updated_at":"2025-06-30T00:34:04.507Z","avatar_url":"https://github.com/ChristianMurphy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Schema KeyRef\n\n[![npm version](https://img.shields.io/npm/v/json-schema-keyref.svg)](https://www.npmjs.com/package/json-schema-keyref)\n[![build status](https://github.com/ChristianMurphy/json-schema-keyref/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/ChristianMurphy/json-schema-keyref/actions/workflows/CI.yml)\n\n## About\n\nThis is an extension to the standard JSON Schema. It allows for validating the\nreferences to remote values, actually have the value that is being referenced.\n\nSee [Example](#example) for a sample use case.\n\n## Installation\n\nInstall from npm\n\n```sh\nnpm install --save json-schema-keyref\n```\n\n## Usage\n\n```js\nconst fs = require(\"fs\");\nconst jsonSchemaKeyref = require(\"json-schema-keyref\");\n\nconst document = JSON.parse(fs.readSync(\"document.json\"));\nconst schema = JSON.parse(fs.readSync(\"schema.json\"));\n\n// Validate document against standard JSON schema using tv4 or another library\n\nconst result = jsonSchemaKeyref.validate(document, schema);\n\nconsole.log(result); //=\u003e {\"errors\": [], \"isValid\": true}\n```\n\n## Example\n\nBelow is a User and Transaction database. Where users have an `id` and `name`.\nAnd transactions are `from` one user `id`, `to` another user `id`, with an\n`amount`.\n\nUsing key reference validator, transaction 2 would be flagged because user 3\ndoes not exist in the data.\n\nData:\n\n```json\n{\n  \"users\": [\n    {\n      \"id\": 1,\n      \"name\": \"user 1\"\n    },\n    {\n      \"id\": 2,\n      \"name\": \"user 2\"\n    }\n  ],\n  \"transactions\": [\n    {\n      \"from\": 1,\n      \"to\": 2,\n      \"amount\": 1.0\n    },\n    {\n      \"from\": 3,\n      \"to\": 1,\n      \"amount\": 99.99\n    }\n  ]\n}\n```\n\nSchema:\n\n```json\n{\n  \"key\": {\n    \"to\": \"$.users[*].id\",\n    \"from\": \"$.users[*].id\"\n  },\n  \"keyref\": {\n    \"to\": \"$.transactions[*].to\",\n    \"from\": \"$.transactions[*].from\"\n  },\n\n  \"title\": \"Employee and Transaction Database\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"users\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"id\": {\n          \"type\": \"integer\"\n        },\n        \"name\": {\n          \"type\": \"string\"\n        }\n      },\n      \"required\": [\"id\", \"name\"]\n    },\n    \"transactions\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"to\": {\n          \"type\": \"integer\"\n        },\n        \"from\": {\n          \"type\": \"integer\"\n        },\n        \"amount\": {\n          \"type\": \"number\"\n        }\n      }\n    }\n  },\n  \"required\": [\"users\", \"transactions\"]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristianmurphy%2Fjson-schema-keyref","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristianmurphy%2Fjson-schema-keyref","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristianmurphy%2Fjson-schema-keyref/lists"}