{"id":27123857,"url":"https://github.com/borgeby/clj-json-pointer","last_synced_at":"2025-04-07T13:18:28.880Z","repository":{"id":63204857,"uuid":"560825530","full_name":"borgeby/clj-json-pointer","owner":"borgeby","description":"Simple Clojure(Script) library for working with JSON Pointer and JSON Patch, with no external dependencies.","archived":false,"fork":false,"pushed_at":"2023-05-29T09:08:05.000Z","size":76,"stargazers_count":6,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T22:42:07.952Z","etag":null,"topics":["clojure","clojurescript","json-patch","json-pointer"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/borgeby.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":"2022-11-02T10:59:25.000Z","updated_at":"2024-08-03T20:45:47.000Z","dependencies_parsed_at":"2023-01-27T16:01:16.738Z","dependency_job_id":null,"html_url":"https://github.com/borgeby/clj-json-pointer","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borgeby%2Fclj-json-pointer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borgeby%2Fclj-json-pointer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borgeby%2Fclj-json-pointer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borgeby%2Fclj-json-pointer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/borgeby","download_url":"https://codeload.github.com/borgeby/clj-json-pointer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247655652,"owners_count":20974208,"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":["clojure","clojurescript","json-patch","json-pointer"],"created_at":"2025-04-07T13:18:28.281Z","updated_at":"2025-04-07T13:18:28.871Z","avatar_url":"https://github.com/borgeby.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cljs-json-pointer\n[![Clojars Project](https://img.shields.io/clojars/v/by.borge/clj-json-pointer.svg)](https://clojars.org/by.borge/clj-json-pointer)\n[![cljdoc](https://cljdoc.org/badge/by.borge/clj-json-pointer)](https://cljdoc.org/d/by.borge/clj-json-pointer)\n![build](https://github.com/borgeby/clj-json-pointer/actions/workflows/check.yml/badge.svg)\n[![codecov](https://codecov.io/github/borgeby/clj-json-pointer/branch/main/graph/badge.svg?token=0T30IGULJ2)](https://codecov.io/github/borgeby/clj-json-pointer)\n\nSimple Clojure(Script) library for working with [JSON Pointer](https://www.rfc-editor.org/rfc/rfc6901) and \n[JSON Patch](https://datatracker.ietf.org/doc/html/rfc6902/), with no external dependencies. The JSON Patch function\nprovided passes all the tests from the JSON patch [conformance test suite](https://github.com/json-patch/json-patch-tests). \n\n## Usage instructions\n\nAt the heart of the library is the `-\u003evec` function, which may be used to transform a JSON pointer into a vector\nrepresenting the path of an object or array. This vector is suitable for use with the standard Clojure functions for\nnested access or updates, like `get-in`, `assoc-in` and `update-in`:\n\n```clojure\n(ns app\n  (:require [clj-json-pointer.core :as jp]))\n\n(def org\n  {\"department\"\n   {\"tech\"\n    {\"users\"\n     [{\"name\" \"ted\"  \"roles\" [\"developer\"]}\n      {\"name\" \"jane\" \"roles\" [\"platform\" \"devops\"]}]}\n    \"finance\"\n    {\"users\"\n     [{\"name\" \"joe\"  \"roles\" [\"reports-writer\"]}]}}})\n\n(let [path (jp/-\u003evec org \"/department/tech/users/1/roles\") ; =\u003e [\"department\" \"tech\" 1 \"users\" \"roles\"]\n      roles (get-in org path)]                             ; =\u003e [\"platform\" \"devops\"]\n  (do (something (with roles))))\n```\n\nThese simple building blocks are used to implement the various operations of JSON `patch`:\n\n```clojure\n(jp/patch {}                                        ; =\u003e {}\n  [{\"op\" \"add\" \"path\" \"/foo\" \"value\" \"bar\"}         ; =\u003e {\"foo\" \"bar\"}\n   {\"op\" \"add\" \"path\" \"/bar\" \"value\" \"baz\"}         ; =\u003e {\"foo\" \"bar\" \"bar\" \"baz}\n   {\"op\" \"remove\" \"path\" \"/foo\"}                    ; =\u003e {\"bar\" \"baz\"}\n   {\"op\" \"replace\" \"path\" \"/bar\" \"value\" \"foo\"}     ; =\u003e {\"bar\" \"foo\"}          \n   {\"op\" \"copy\" \"from\" \"/bar\" \"path\" \"/baz\"}        ; =\u003e {\"bar\" \"foo\" \"baz\" \"foo\"}                \n   {\"op\" \"move\" \"from\" \"/baz\" \"path\" \"/foo\"}        ; =\u003e {\"foo\" \"foo\"}\n   {\"op\" \"test\" \"path\" \"/foo\" \"value\" \"foo\"}])      ; =\u003e {\"foo\" \"foo\"}\n```\n\nOr if you so prefer, use the `apply-patch` function, which applies a single patch to the provided data structure:\n\n```clojure\n(jp/apply-patch {} {\"op\" \"add\" \"path\" \"/a\" \"value\" 1}) ; =\u003e {\"a\" 1}\n\n; or, more likely:\n(reduce jp/apply-patch {} patches)\n```\n\n## Development\n\n### Test\n\n* `clj -X:test` to run the unit and compliance tests\n* `shadow-cljs compile test \u0026\u0026 node target/cljs-test.js` for ClojureScript\n\n### Deploy\n\n* `clj -T:build jar`\n* `clj -X:deploy`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborgeby%2Fclj-json-pointer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborgeby%2Fclj-json-pointer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborgeby%2Fclj-json-pointer/lists"}