{"id":23737776,"url":"https://github.com/react-querybuilder/json-logic-js","last_synced_at":"2026-02-28T20:30:16.871Z","repository":{"id":235337349,"uuid":"774095193","full_name":"react-querybuilder/json-logic-js","owner":"react-querybuilder","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-18T23:53:05.000Z","size":171,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-31T08:20:05.052Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/react-querybuilder.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-18T23:49:58.000Z","updated_at":"2024-04-25T23:36:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"d7c7c846-733e-4f9b-b2df-893cca5cd28a","html_url":"https://github.com/react-querybuilder/json-logic-js","commit_stats":null,"previous_names":["react-querybuilder/json-logic-js"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-querybuilder%2Fjson-logic-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-querybuilder%2Fjson-logic-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-querybuilder%2Fjson-logic-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/react-querybuilder%2Fjson-logic-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/react-querybuilder","download_url":"https://codeload.github.com/react-querybuilder/json-logic-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239878085,"owners_count":19712164,"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":[],"created_at":"2024-12-31T08:19:59.174Z","updated_at":"2026-02-28T20:30:16.792Z","avatar_url":"https://github.com/react-querybuilder.png","language":"TypeScript","readme":"# @react-querybuilder/json-logic-js\n\n\u003e _This fork of [json-logic-js](https://github.com/jwadhams/json-logic-js), originally by [Jeremy Wadhams](https://github.com/jwadhams), is used by [`React Query Builder`](https://react-querybuilder.js.org/) but has no dependencies itself._\n\nThis parser accepts [JsonLogic](http://jsonlogic.com) rules and executes them in JavaScript.\n\nThe JsonLogic format is designed to allow you to share rules (logic) between front-end and back-end code (regardless of language difference), even to store logic along with a record in a database. JsonLogic is documented extensively at [JsonLogic.com](http://jsonlogic.com), including examples of every [supported operation](http://jsonlogic.com/operations.html) and a place to [try out rules in your browser](http://jsonlogic.com/play.html).\n\nThe same format can also be executed in PHP by the library [json-logic-php](https://github.com/jwadhams/json-logic-php/)\n\n## Installation\n\nPackage manager:\n\n```bash\nnpm install @react-querybuilder/json-logic-js\n# OR yarn add / pnpm add / bun add\n```\n\nCDN:\n\n```html\n\u003c!-- ESM: --\u003e\n\u003cscript type=\"module\"\u003e\n  import jsonLogic from \"https://cdn.jsdelivr.net/npm/@react-querybuilder/json-logic-js+esm\";\n  // ...\n\u003c/script\u003e\n\n\u003c!-- UMD: --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/@react-querybuilder/json-logic-js/dist/json-logic.umd.min.js\"\u003e\u003c/script\u003e\n```\n\n## Examples\n\n### Simple\n\n```js\njsonLogic.apply({ \"==\": [1, 1] });\n// true\n```\n\nThis is a simple test, equivalent to `1 == 1`. A few things about the format:\n\n1. The operator is always in the \"key\" position. There is only one key per JsonLogic rule.\n2. The values are typically an array.\n3. Each value can be a string, number, boolean, array (non-associative), or null\n\n### Compound\n\nHere we're beginning to nest rules.\n\n```js\njsonLogic.apply({ and: [{ \"\u003e\": [3, 1] }, { \"\u003c\": [1, 3] }] });\n// true\n```\n\nIn an infix language (like JavaScript) this could be written as:\n\n```js\n3 \u003e 1 \u0026\u0026 1 \u003c 3;\n```\n\n### Data-Driven\n\nObviously these rules aren't very interesting if they can only take static literal data. Typically `jsonLogic.apply` will be called with a rule object and a data object. You can use the `var` operator to get attributes of the data object:\n\n```js\njsonLogic.apply(\n  { var: [\"a\"] }, // Rule\n  { a: 1, b: 2 } // Data\n);\n// 1\n```\n\nWe support [syntactic sugar](https://en.wikipedia.org/wiki/Syntactic_sugar) on unary operators like `var` to skip the array around values:\n\n```js\njsonLogic.apply({ var: \"a\" }, { a: 1, b: 2 });\n// 1\n```\n\nYou can also use the `var` operator to access an array by numeric index:\n\n```js\njsonLogic.apply({ var: 1 }, [\"apple\", \"banana\", \"carrot\"]);\n// \"banana\"\n```\n\nHere's a complex rule that mixes literals and data. The pie isn't ready to eat unless it's cooler than 110 degrees, _and_ filled with apples.\n\n```js\nvar rules = {\n  and: [\n    { \"\u003c\": [{ var: \"temp\" }, 110] },\n    { \"==\": [{ var: \"pie.filling\" }, \"apple\"] },\n  ],\n};\n\nvar data = { temp: 100, pie: { filling: \"apple\" } };\n\njsonLogic.apply(rules, data);\n// true\n```\n\n### Always and Never\n\nSometimes the rule you want to process is \"Always\" or \"Never.\" If the first parameter passed to `jsonLogic` is a non-object, non-associative-array, it is returned immediately.\n\n```js\n//Always\njsonLogic.apply(true, data_will_be_ignored);\n// true\n\n//Never\njsonLogic.apply(false, i_wasnt_even_supposed_to_be_here);\n// false\n```\n\n## Customization\n\nIt's not possible to include everyone's excellent ideas without the core library bloating, bringing in a ton of outside dependencies, or occasionally causing use case conflicts (some people need to safely execute untrusted rules, some people need to change outside state).\n\nCheck out the [documentation for adding custom operations](http://jsonlogic.com/add_operation.html) and be sure to stop by the original [wiki page of custom operations](https://github.com/jwadhams/json-logic-js/wiki/Custom-Operations) to see if someone has already solved your problem or to share your solution.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-querybuilder%2Fjson-logic-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freact-querybuilder%2Fjson-logic-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freact-querybuilder%2Fjson-logic-js/lists"}