{"id":32151836,"url":"https://github.com/advantagefse/json-logic-swift","last_synced_at":"2025-10-21T10:53:48.850Z","repository":{"id":34361409,"uuid":"177568047","full_name":"advantagefse/json-logic-swift","owner":"advantagefse","description":"A native Swift JsonLogic implementation. This parser accepts JsonLogic rules and executes them. ","archived":false,"fork":false,"pushed_at":"2024-05-29T10:22:04.000Z","size":167,"stargazers_count":30,"open_issues_count":4,"forks_count":22,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-21T10:53:41.849Z","etag":null,"topics":["cocoapods","ios","json","jsonlogic","spm","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/advantagefse.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}},"created_at":"2019-03-25T10:53:39.000Z","updated_at":"2025-06-09T06:21:33.000Z","dependencies_parsed_at":"2024-06-19T16:14:09.105Z","dependency_job_id":null,"html_url":"https://github.com/advantagefse/json-logic-swift","commit_stats":{"total_commits":64,"total_committers":6,"mean_commits":"10.666666666666666","dds":0.1875,"last_synced_commit":"9088eed1b26937fe13d248aa24d7632a51be28e2"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/advantagefse/json-logic-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/advantagefse%2Fjson-logic-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/advantagefse%2Fjson-logic-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/advantagefse%2Fjson-logic-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/advantagefse%2Fjson-logic-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/advantagefse","download_url":"https://codeload.github.com/advantagefse/json-logic-swift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/advantagefse%2Fjson-logic-swift/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280248569,"owners_count":26297925,"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-21T02:00:06.614Z","response_time":58,"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":["cocoapods","ios","json","jsonlogic","spm","swift"],"created_at":"2025-10-21T10:53:44.928Z","updated_at":"2025-10-21T10:53:48.843Z","avatar_url":"https://github.com/advantagefse.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jsonlogic-swift\n\n[![CI Status](http://img.shields.io/travis/advantagefse/json-logic-swift.svg?style=flat)](https://travis-ci.org/advantagefse/json-logic-swift)\n[![Version](https://img.shields.io/cocoapods/v/jsonlogic.svg?style=flat)](https://cocoapods.org/pods/jsonlogic)\n[![Platform](https://img.shields.io/cocoapods/p/jsonlogic.svg?style=flat)](https://cocoapods.org/pods/jsonlogic)\n[![codecov](https://codecov.io/gh/advantagefse/json-logic-swift/branch/master/graph/badge.svg)](https://codecov.io/gh/advantagefse/json-logic-swift)\n\nA native Swift JsonLogic implementation. This parser accepts [JsonLogic](http://jsonlogic.com) \nrules and executes them. \n\nJsonLogic is a way to write rules that involve computations in JSON \nformat, these can be applied on JSON data with consistent results. So you can share between server and clients rules in a common format. Original JS JsonLogic implementation is developed by Jeremy Wadhams.\n\n## Instalation\n\n#### Using CocoaPods\n\nTo use the pod in your project add in the Podfile:\n\n    pod jsonlogic\n\nTo run the example project, just run:\n\n    pod try jsonlogic    \n\n#### Using Swift Package Manager\n\nif you use Swift Package Manager add the following in dependencies:\n\n        dependencies: [\n        .package(\n            url: \"https://github.com/advantagefse/json-logic-swift\", from: \"1.0.0\"\n        )\n    ]\n\n## Usage\n\nYou simply import the module and either call the applyRule global method:\n\n```swift\nimport jsonlogic\n\nlet rule =\n\"\"\"\n{ \"var\" : \"name\" }\n\"\"\"\nlet data =\n\"\"\"\n{ \"name\" : \"Jon\" }\n\"\"\"\n\n//Example parsing\nlet result: String? = try? applyRule(rule, to: data)\n\nprint(\"result = \\(String(describing: result))\")\n```\n\nThe ```applyRule``` will parse the rule then apply it to the ```data``` and try to convert the \nresult to\n the \ninferred return \ntype, \nif it fails an error will be thrown.\n\nIf you need to apply the same rule to multiple data then it will be better to parse the rule once.\nYou can do this by initializing a ```JsonRule``` object with the rule and then calling \n```applyRule```.\n\n```swift\n\n//Example parsing\nlet jsonlogic = try JsonLogic(rule)\n\nvar result: Bool = jsonlogic.applyRule(to: data1)\nresult = jsonlogic.applyRule(to: data2)\n//etc..\n\n```\n\n## Examples\n\n#### Simple\n```Swift\nlet rule = \"\"\"\n{ \"==\" : [1, 1] }\n\"\"\"\n\nlet result: Bool = try applyRule(rule)\n//evaluates to true\n```\n\nThis is a simple test, equivalent to `1 == 1`.  A few things about the format:\n\n  1. The operator is always in the \"key\" position. There is only one key per JsonLogic rule.\n  1. The values are typically an array.\n  1. Each value can be a string, number, boolean, array (non-associative), or null\n\n#### Compound\nHere we're beginning to nest rules.\n\n```Swift\nlet rule = \"\"\"\n  {\"and\" : [\n    { \"\u003e\" : [3,1] },\n    { \"\u003c\" : [1,3] }\n  ] }\n\"\"\"\nlet result: Bool = try applyRule(rule)\n//evaluates to true\n```\n\nIn an infix language this could be written as:\n\n```Swift\n( (3 \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. \nTypically `jsonLogic` will be called with a rule object and a data object. You can use the `var` \noperator to get attributes of the data object:\n\n```Swift\nlet rule = \"\"\"\n  { \"var\" : [\"a\"] }\n\"\"\"\nlet data = \"\"\"\n  { a : 1, b : 2 }\n\"\"\"\nlet result: Int = try applyRule(rule, to: data)\n//evaluates to 1\n```\n\nIf you like, we support to skip the array around values:\n\n```Swift\nlet rule = \"\"\"\n  { \"var\" : \"a\" }\n\"\"\"\nlet data = \"\"\"\n  { a : 1, b : 2 }\n\"\"\"\nlet result: Int = try applyRule(rule, to: data)\n//evaluates to 1\n```\n\nYou can also use the `var` operator to access an array by numeric index:\n\n```js\njsonLogic.apply(\n  {\"var\" : 1 },\n  [ \"apple\", \"banana\", \"carrot\" ]\n);\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```Swift\nlet rule = \"\"\"\n{ \"and\" : [\n  {\"\u003c\" : [ { \"var\" : \"temp\" }, 110 ]},\n  {\"==\" : [ { \"var\" : \"pie.filling\" }, \"apple\" ] }\n] }\n\"\"\"\nlet data = \"\"\"\n  { \"temp\" : 100, \"pie\" : { \"filling\" : \"apple\" } }\n\"\"\"\n\nlet result: Bool = try applyRule(rule, to: data)\n//evaluates to true\n```\n\n### Custom operators\n\nYou can register a custom operator\n\n```Swift\nimport jsonlogic\nimport JSON\n\n// the key is the operator and the value is a closure that takes as argument\n// a JSON and returns a JSON\nlet customRules =\n    [\"numberOfElementsInArray\": { (json: JSON?) -\u003e JSON in                                 \n        switch json {\n        case let .Array(array):\n            return JSON(array.count)\n        default:\n            return JSON(0)\n        }\n    }]\n    \nlet rule = \"\"\"\n    { \"numberOfElementsInArray\" : [1, 2, 3] }\n\"\"\"\n    \n// The value is 3\nlet value: Int = try JsonLogic(rule, customOperators: customRules).applyRule()\n```\n\n### Other operators\n\nFor a complete list of the supported operators and their usages see [jsonlogic operators](http://jsonlogic.com/operations.html).\n\n### Command Line Interface\n\nComming soon...\n\n## Contributing\n\nMaking changes are welcome. \nIf you find a bug please submit a unit test that reproduces it, before submitting the fix.\n\nBecause the project was created and build using the Swift PM there is no Xcode project file \ncommitted in the repo. If you need one you can generated by running ```genenate-xcodeproj.sh ``` \nin the terminal:\n\n```\n$ . generate-xcodeproj.sh\n```\n\n## Requirements\n\n\n| iOS      | tvOS       | watchOS    | macOS      |\n| :------: |:----------:|:----------:|:----------:|\n| \u003e=9.0    | \u003e=10.0     | \u003e=2.0      | \u003e=10.12    |\n\n\n## Author\n\nChristos Koninis, c.koninis@afse.eu\n\n## License\n\nJsonLogic for Swift is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadvantagefse%2Fjson-logic-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadvantagefse%2Fjson-logic-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadvantagefse%2Fjson-logic-swift/lists"}