{"id":19506898,"url":"https://github.com/svroonland/play-json-optics","last_synced_at":"2026-02-27T03:02:03.026Z","repository":{"id":41874998,"uuid":"129370148","full_name":"svroonland/play-json-optics","owner":"svroonland","description":"Monocle optics/lenses for Play! JSON","archived":false,"fork":false,"pushed_at":"2024-06-25T04:06:10.000Z","size":48,"stargazers_count":10,"open_issues_count":10,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-24T17:31:28.726Z","etag":null,"topics":["event-sourcing","monocle","optics","play-json","schema-evolution"],"latest_commit_sha":null,"homepage":null,"language":"Scala","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/svroonland.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":"2018-04-13T08:06:42.000Z","updated_at":"2022-12-16T15:50:26.000Z","dependencies_parsed_at":"2025-04-26T03:03:13.774Z","dependency_job_id":null,"html_url":"https://github.com/svroonland/play-json-optics","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/svroonland/play-json-optics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svroonland%2Fplay-json-optics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svroonland%2Fplay-json-optics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svroonland%2Fplay-json-optics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svroonland%2Fplay-json-optics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/svroonland","download_url":"https://codeload.github.com/svroonland/play-json-optics/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/svroonland%2Fplay-json-optics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29883111,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T23:51:21.483Z","status":"online","status_checked_at":"2026-02-27T02:00:06.759Z","response_time":57,"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":["event-sourcing","monocle","optics","play-json","schema-evolution"],"created_at":"2024-11-10T22:38:51.359Z","updated_at":"2026-02-27T03:02:03.011Z","avatar_url":"https://github.com/svroonland.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![Bintray](https://img.shields.io/bintray/v/vroste/maven/play-json-optics?label=latest)](https://bintray.com/vroste/maven/play-json-optics/_latestVersion)\n[![CircleCI](https://circleci.com/gh/svroonland/play-json-optics.svg?style=svg)](https://circleci.com/gh/svroonland/play-json-optics)\n\n# play-json-optics\nMonocle optics for Play! JSON data types. \n\n## About \nThis libary allows easy creation of complex, composable JSON-to-JSON transformations with `play-json`.\n\nIn event sourcing applications or JSON-based APIs, the need to be backwards compatible with older versions of JSON data often means \nwriting complex transformations from the old to the new structure. Although [Play Json Transformers](https://www.playframework.com/documentation/2.6.x/ScalaJsonTransformers) \noffer support for this, the syntax is rather cumbersome, error prone and becomes unwieldly for even typical transformations like modifying optional fields.\n\nThe optics from [Monocle](http://julien-truffaut.github.io/Monocle/) offer very powerful abstractions to assist in transforming Json. This library brings the power of `monocle` to `play-json`, together with some convenience methods for expressing common transformations.\n\nThings you can do with this library:\n* modify the type of JSON values\n* set default values for missing values\n* modify values deep inside a JSON structure as instances of your own data types\n* apply modifications on arrays of values\n* rename fields\n* move substructures within the JSON to a different path\n\nOptics to any path within a JSON data structure can be expressed using `play-json`'s path syntax, eg `__ \\ \"user\" \\ \"name\"`.\n\n## Usage\nAdd the following to your build.sbt:\n\n```\nresolvers += Resolver.bintrayRepo(\"vroste\", \"maven\"),\nlibraryDependencies += \"nl.vroste\" %% \"play-json-optics\" % \"0.2.0.0\"\n```\n\n## Version compatibility\n\n| Version | Play-json | Scala          | Cats |\n| ------- | --------- | -------------- | ---- |\n| 0.2.0.0 | 2.7       | 2.13\u003cbr /\u003e2.12 | 2    |\n| 0.1.1.0 | 2.6       | 2.12           | 1    |\n\n## Example\n\n### Change strings to booleans in an array of Json objects\n```scala\nimport nl.vroste.playjsonoptics.JsLens\nimport play.api.libs.json._\n\nval json = Json.parse(\"\"\" \n{\n  \"times\": [\n    {\n      \"time\": \"2018-01-30T12:30:24Z\"\n    },\n    {\n      \"time\": \"2018-01-30T12:30:24Z\",\n      \"estimateOrActual\": \"ESTIMATE\"\n    }\n  ]\n}\"\"\")\n\nval modifyOne = JsLens[JsValue](__ \\ \"estimateOrActual\").modify {\n  case JsString(e) =\u003e JsBoolean(e == \"ESTIMATE\")\n  case _           =\u003e JsBoolean(false)\n}\n\nval modifyAll = JsLens.each[JsValue](__ \\ \"times\") composeOptional modifyOne\n\nmodifyAll(json) \n```\nwill produce: \n```json\n{\n  \"times\": [\n    {\n      \"time\": \"2018-01-30T12:30:24Z\"\n    },\n    {\n      \"time\": \"2018-01-30T12:30:24Z\",\n      \"estimateOrActual\": true\n    }\n  ]\n}\n```\n\n### Transform with custom types\n```scala\nJsLens[Instant](__ \\ \"time\") modify (_.plus(1, DAYS)))\n```\n\n### Set default value\n```scala\n(__ \\ \"estimateOrActual\").setDefault[String](\"DEFAULT\")\n```\n\n### Move substructures\n```scala\n(__ \\ \"times\") moveTo (__ \\ \"nested\" \\ \"datetimes\")\n```\n### More examples\nSee [TransformationExamples](https://github.com/svroonland/play-json-optics/blob/master/playjsonoptics/src/test/scala/com/vroste/playjsonoptics/examples/TransformationExamples.scala)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvroonland%2Fplay-json-optics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsvroonland%2Fplay-json-optics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsvroonland%2Fplay-json-optics/lists"}