{"id":16898074,"url":"https://github.com/radeusgd/jsonrewriter","last_synced_at":"2026-05-09T19:41:27.178Z","repository":{"id":153769432,"uuid":"124302679","full_name":"radeusgd/JSONRewriter","owner":"radeusgd","description":"Scala utility for converting data in JSON between expected formats","archived":false,"fork":false,"pushed_at":"2018-03-08T21:18:08.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-25T11:41:32.967Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/radeusgd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-03-07T22:33:33.000Z","updated_at":"2018-03-07T23:16:44.000Z","dependencies_parsed_at":"2023-07-05T00:34:03.767Z","dependency_job_id":null,"html_url":"https://github.com/radeusgd/JSONRewriter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radeusgd%2FJSONRewriter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radeusgd%2FJSONRewriter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radeusgd%2FJSONRewriter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radeusgd%2FJSONRewriter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/radeusgd","download_url":"https://codeload.github.com/radeusgd/JSONRewriter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244600986,"owners_count":20479369,"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-10-13T17:41:01.857Z","updated_at":"2026-05-09T19:41:27.137Z","avatar_url":"https://github.com/radeusgd.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Rewriter\nA functional utility library for quickly writing JSON converters.\n\nUseful for situations when you have two endpoints using JSON \nthat communicate similar data, however in slightly different formats. \n\n## Examples\n\nFull code is in `examples` package.\n\n#### [Example 1] Convert some formats\nInput:\n\n```\n{\"user\":{\"age\": 30, \"names\": \"Jack Oliver Jake\", \"lastname\": \"King\"}, \"profile\": {\"adclicks\": [0,1,2,3]}}\n{\"user\":{\"age\": 45, \"names\": \"Emma Amelia Margaret\", \"lastname\": \"Smith\"}, \"profile\": {\"adclicks\": [0,1]}}\n{\"user\":{\"age\": 26, \"names\": \"Thomas\", \"lastname\": \"Martin\"}, \"profile\": {\"adclicks\": []}}\n```\n\nConversion function:\n\n```scala\nval convert: JsValue =\u003e JsValue =\n    asJsObject _ |\u003e compose[JsObject](\n        _.mapChild(\"user\", _.asJsObject.rename(\"lastname\", \"surname\")), // rename property\n        _.mapDescendant(\"user.age\", (j: JsValue) =\u003e j.asJsNumber.map(_ * 365)), // estimate age in days\n        _.mapDescendant(\"user.names\", (j: JsValue) =\u003e // convert names to array of strings\n           JsArray(j.asString.split(' ').toVector.map(JsString(_))))\n    )\n```\n      \nOutput:\n```\n{\"user\":{\"age\":10950,\"names\":[\"Jack\",\"Oliver\",\"Jake\"],\"surname\":\"King\"},\"profile\":{\"adclicks\":[0,1,2,3]}}\n{\"user\":{\"age\":16425,\"names\":[\"Emma\",\"Amelia\",\"Margaret\"],\"surname\":\"Smith\"},\"profile\":{\"adclicks\":[0,1]}}\n{\"user\":{\"age\":9490,\"names\":[\"Thomas\"],\"surname\":\"Martin\"},\"profile\":{\"adclicks\":[]}}\n```\n\n#### [Example 2] Group keys into objects\nInput:\n\n```\n{\"name\": \"John\", \"mother_name\": \"Emma\", \"mother_age\": 35, \"father_name\": \"Thomas\", \"father_age\": 40}\n{\"name\": \"Emma\", \"mother_name\": \"Olivia\", \"mother_age\": 30, \"father_name\": \"Jack\", \"father_age\": 29}\n```\n\nConversion function:\n\n```scala\nval groupParents: JsValue =\u003e JsValue =\n    asJsObject _ |\u003e compose[JsObject](\n        _.groupAndRename(Map(\"mother_name\" -\u003e \"name\", \"mother_age\" -\u003e \"age\"), \"mother\"),\n        _.groupAndRename(Map(\"father_name\" -\u003e \"name\", \"father_age\" -\u003e \"age\"), \"father\")\n    )\n```\n      \nOutput:\n```\n{\"mother\":{\"name\":\"Emma\",\"age\":35},\"name\":\"John\",\"father\":{\"name\":\"Thomas\",\"age\":40}}\n{\"mother\":{\"name\":\"Olivia\",\"age\":30},\"name\":\"Emma\",\"father\":{\"name\":\"Jack\",\"age\":29}}\n```\n\n#### [Example 3] Group keys into an array\nInput:\n\n```\n{\"bikeid\": \"RC4963\", \"owner1\": \"Peter\", \"owner2\": \"Amelia\", \"owner3\": \"Jack\", \"owner4\": \"John\"}\n{\"bikeid\": \"RK2528\", \"owner1\": \"Thomas\", \"owner2\": null, \"owner3\": \"Jack\", \"owner4\": \"Margaret\", \"repairs\": 4}\n{\"bikeid\": \"RC4694\", \"owner1\": null, \"owner2\": null, \"owner3\": null, \"owner4\": null}\n```\n\nConversion function:\n\n```scala\nval arrayize: JsValue =\u003e JsValue =\n    asJsObject _ |\u003e compose[JsObject](\n        _.mapChildrenToArray(Vector(\"owner1\", \"owner2\", \"owner3\", \"owner4\"), \"owners\"),\n        _.mapChild(\"owners\", _.asJsArray.filter(_ != JsNull)) // throw away empty values\n    )\n```\n      \nOutput:\n```\n{\"owners\":[\"Peter\",\"Amelia\",\"Jack\",\"John\"],\"bikeid\":\"RC4963\"}\n{\"owners\":[\"Thomas\",\"Jack\",\"Margaret\"],\"bikeid\":\"RK2528\",\"repairs\":4}\n{\"owners\":[],\"bikeid\":\"RC4694\"}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradeusgd%2Fjsonrewriter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradeusgd%2Fjsonrewriter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradeusgd%2Fjsonrewriter/lists"}