{"id":15063880,"url":"https://gitlab.com/igrep/deriveJsonNoPrefix","last_synced_at":"2025-09-25T21:31:14.747Z","repository":{"id":59152032,"uuid":"7501538","full_name":"igrep/deriveJsonNoPrefix","owner":"igrep","description":"Template Haskell macros to derive ToJSON/FromJSON instances in a more prefix-friendly manner.","archived":false,"fork":false,"pushed_at":null,"size":null,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":null,"default_branch":"master","last_synced_at":"2024-04-25T23:31:23.299Z","etag":null,"topics":["haskell","json","template haskell"],"latest_commit_sha":null,"homepage":null,"language":null,"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":null,"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}},"created_at":"2018-07-16T05:32:34.313Z","updated_at":"2018-07-17T08:29:21.810Z","dependencies_parsed_at":"2022-09-13T11:00:55.083Z","dependency_job_id":null,"html_url":"https://gitlab.com/igrep/deriveJsonNoPrefix","commit_stats":null,"previous_names":[],"tags_count":2,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repositories/igrep%2FderiveJsonNoPrefix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repositories/igrep%2FderiveJsonNoPrefix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repositories/igrep%2FderiveJsonNoPrefix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repositories/igrep%2FderiveJsonNoPrefix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/owners/igrep","download_url":"https://gitlab.com/igrep/deriveJsonNoPrefix/-/archive/master/deriveJsonNoPrefix-master.zip","host":{"name":"gitlab.com","url":"https://gitlab.com","kind":"gitlab","repositories_count":4516561,"owners_count":6607,"icon_url":"https://github.com/gitlab.png","version":null,"created_at":"2022-05-30T11:31:42.605Z","updated_at":"2024-07-18T11:24:13.055Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/gitlab.com/owners"}},"keywords":["haskell","json","template haskell"],"created_at":"2024-09-25T00:08:25.561Z","updated_at":"2025-09-25T21:31:09.331Z","avatar_url":null,"language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# deriveJsonNoPrefix\n\nTemplate Haskell macros to derive ToJSON/FromJSON instances in a more prefix-friendly manner.\n\n## Example\n\nSuppose you want to create a JSON like this:\n\n```json\n{\n    \"id\": \"ID STRING\",\n    \"max\": 0.789,\n    \"min\": 0.123\n}\n```\n\nYou'd want to define a record type to derive the instance of [ToJSON](http://hackage.haskell.org/package/aeson/docs/Data-Aeson.html#t:ToJSON) (and possibly [FromJSON](http://hackage.haskell.org/package/aeson/docs/Data-Aeson.html#t:FromJSON)) automatically:\n\n```hs\n{-# LANGUAGE TemplateHaskell #-}\n\nimport Data.Aeson.TH\n\ndata SomeRecord = SomeRecord\n  { id :: String\n  , max :: Double\n  , min :: Double\n  } deriving (Eq, Show)\n\n$(deriveToJSON ''SomeRecord)\n```\n\nBut you shouldn't define such a record because both `id`, `max`, and `min` are predefined functions of `Prelude`!!\n\nAs a workaround, we frequently prefix the record labels with their type name:\n\n```hs\ndata SomeRecord = SomeRecord\n  { someRecordId :: String\n  , someRecordMax :: Double\n  , someRecordMin :: Double\n  } deriving (Eq, Show)\n```\n\nThen `deriveToJSON` with a modified option:\n\n```hs\nderiveToJSON Json.defaultOptions { fieldLabelModifier = firstLower . drop (length \"SomeRecord\") } ''SomeRecord\n\nfirstLower :: String -\u003e String\nfirstLower (x:xs) = toLower x : xs\nfirstLower _ = error \"firstLower: Assertion failed: empty string\"\n```\n\nThat's almost exactly what `deriveToJsonNoTypeNamePrefix` does!!  \n`deriveToJsonNoTypeNamePrefix` is essentially defined as:\n\n```hs\nderiveToJsonNoTypeNamePrefix :: Name -\u003e Q [Dec]\nderiveToJsonNoTypeNamePrefix deriver name =\n  deriveToJSON Json.defaultOptions { fieldLabelModifier = dropPrefix name } name\n\ndropPrefix :: Name -\u003e String -\u003e String\ndropPrefix name = firstLower . drop (length $ nameBase name)\n\nfirstLower :: String -\u003e String\nfirstLower (x:xs) = toLower x : xs\nfirstLower _ = error \"firstLower: Assertion failed: empty string\"\n```\n\nSo now, you don't have reimplement the `fieldLabelModifier` anymore!\n\n```hs\nimport Data.Aeson.DeriveNoPrefix\n\n$(deriveJsonNoTypeNamePrefix ''SomeRecord)\n```\n\n## Other libraries which would solve the same problem\n\n- [extensible](https://hackage.haskell.org/package/extensible).\n- And other libraries providing extensible records with `ToJSON` / `FromJSON` instances.\n\nSo use this package all of them are too heavy in learning cost / dependency footprint / etc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/gitlab.com%2Figrep%2FderiveJsonNoPrefix","html_url":"https://awesome.ecosyste.ms/projects/gitlab.com%2Figrep%2FderiveJsonNoPrefix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/gitlab.com%2Figrep%2FderiveJsonNoPrefix/lists"}