Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andre-dietrich/elm-generic
An intermediate generic type system for elm
https://github.com/andre-dietrich/elm-generic
Last synced: 19 days ago
JSON representation
An intermediate generic type system for elm
- Host: GitHub
- URL: https://github.com/andre-dietrich/elm-generic
- Owner: andre-dietrich
- License: bsd-3-clause
- Created: 2020-03-06T15:14:18.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-07-05T14:53:05.000Z (over 3 years ago)
- Last Synced: 2024-05-01T13:58:44.831Z (7 months ago)
- Language: Elm
- Size: 36.1 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-generic
This generic type-system can be used as an intermediate representation (lingua
franca), for JSON, YAML, and XML at the moment. Other formats like TOML, MessagePack,
ProtoBuf, Eon, XML might come later and can be used similary. The basic idea is
to have one general abstraction, that can be used to decode multiple formats and
translate between them. But in most cases you will only want to change some
values or extract them, without developing custom decoders and encoders. Thus,
data might be incorrect or some JSON formats might change, but you simply do not
care and extract the pieces, you are interested in.``` elm
import Generic as Gen
import Generic.Json as Json
import Generic.Yaml as Yaml
import Html exposing (Html)main : Html msg
main =
"""
{
"problems": [{
"Diabetes":[{
"medications":[{
"medicationsClasses":[{
"className":[{
"associatedDrug":[{
"name":"asprin",
"dose":"",
"strength":"500 mg"
}],
"associatedDrug#2":[{
"name":"somethingElse",
"dose":"",
"strength":"500 mg"
}]
}],
"className2":[{
"associatedDrug":[{
"name":"asprin",
"dose":"",
"strength":"500 mg"
}],
"associatedDrug#2":[{
"name":"somethingElse",
"dose":"",
"strength":"500 mg"
}]
}]
}]
}],
"labs":[{
"missing_field": "missing_value"
}]
}],
"Asthma":[{}]
}]}"""
|> Json.decodeString
|> Yaml.encode
|> Yaml.toString 2
|> Html.text
|> List.singleton
|> Html.pre []
```