{"id":13561528,"url":"https://github.com/elm/json","last_synced_at":"2025-07-06T00:35:41.923Z","repository":{"id":43256176,"uuid":"118832635","full_name":"elm/json","owner":"elm","description":"Work with JSON in Elm","archived":false,"fork":false,"pushed_at":"2024-06-12T11:26:43.000Z","size":39,"stargazers_count":91,"open_issues_count":22,"forks_count":25,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-09T22:18:35.684Z","etag":null,"topics":["elm","json"],"latest_commit_sha":null,"homepage":"https://package.elm-lang.org/packages/elm/json/latest/","language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elm.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":"2018-01-24T22:56:10.000Z","updated_at":"2024-12-08T16:37:50.000Z","dependencies_parsed_at":"2024-08-01T13:17:17.135Z","dependency_job_id":"64ae100f-df10-4e0e-a122-9e5190c5b955","html_url":"https://github.com/elm/json","commit_stats":{"total_commits":40,"total_committers":3,"mean_commits":"13.333333333333334","dds":"0.050000000000000044","last_synced_commit":"0206c00884af953f2cba8823fee111ee71a0330e"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/elm/json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Fjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Fjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Fjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Fjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elm","download_url":"https://codeload.github.com/elm/json/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elm%2Fjson/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263832177,"owners_count":23517347,"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":["elm","json"],"created_at":"2024-08-01T13:00:57.918Z","updated_at":"2025-07-06T00:35:41.892Z","avatar_url":"https://github.com/elm.png","language":"Elm","funding_links":[],"categories":["Elm"],"sub_categories":[],"readme":"# JSON in Elm\n\nThis package helps you convert between Elm values and JSON values.\n\nThis package is usually used alongside [`elm/http`](http://package.elm-lang.org/packages/elm/http/latest) to talk to servers or [ports](https://guide.elm-lang.org/interop/ports.html) to talk to JavaScript.\n\n\n## Example\n\nHave you seen this [causes of death](https://en.wikipedia.org/wiki/List_of_causes_of_death_by_rate) table? Did you know that in 2002, war accounted for 0.3% of global deaths whereas road traffic accidents accounted for 2.09% and diarrhea accounted for 3.15%?\n\nThe table is interesting, but say we want to visualize this data in a nicer way. We will need some way to get the cause-of-death data from our server, so we create encoders and decoders:\n\n```elm\nmodule Cause exposing (Cause, encode, decoder)\n\nimport Json.Decode as D\nimport Json.Encode as E\n\n\n-- CAUSE OF DEATH\n\ntype alias Cause =\n  { name : String\n  , percent : Float\n  , per100k : Float\n  }\n\n\n-- ENCODE\n\nencode : Cause -\u003e E.Value\nencode cause =\n  E.object\n    [ (\"name\", E.string cause.name)\n    , (\"percent\", E.float cause.percent)\n    , (\"per100k\", E.float cause.per100k)\n    ]\n\n\n-- DECODER\n\ndecoder : D.Decoder Cause\ndecoder =\n  D.map3 Cause\n    (D.field \"name\" D.string)\n    (D.field \"percent\" D.float)\n    (D.field \"per100k\" D.float)\n```\n\nNow in some other code we can use `Cause.encode` and `Cause.decoder` as building blocks. So if we want to decode a list of causes, saying `Decode.list Cause.decoder` will handle it!\n\nPoint is, the goal should be:\n\n  1. Make small JSON decoders and encoders.\n  2. Snap together these building blocks as needed.\n\nSo say you decide to make the `name` field more precise. Instead of a `String`, you want to use codes from the [International Classification of Diseases](http://www.who.int/classifications/icd/en/) recommended by the World Health Organization. These [codes](http://apps.who.int/classifications/icd10/browse/2016/en) are used in a lot of mortality data sets. So it may make sense to make a separate `IcdCode` module with its own `IcdCode.encode` and `IcdCode.decoder` that ensure you are working with valid codes. From there, you can use them as building blocks in the `Cause` module!\n\n\n## Future Plans\n\nIt is easy to get focused on how to optimize the use of JSON, but I think this is missing the bigger picture. Instead, I would like to head towards [this vision](https://gist.github.com/evancz/1c5f2cf34939336ecb79b97bb89d9da6) of data interchange.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felm%2Fjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felm%2Fjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felm%2Fjson/lists"}