If you are looking for a way to deserialize and serialize JSON values in Elm, this package might not be what you are looking for! If you've never read the docs for elm/json, I suggest you go do that first.
Most of the time, your use-case for "doing JSON" looks something like this:
For that, elm/json remains undefeated.
However, sometimes you don't know, need to know, or want to care about the JSON in your Elm program. Sometimes, you want to handle a JSON value by storing some kind of information about the structure of that JSON value. For instance - what if you need to let your users map some value from an incoming webhook payload, to an input in your application? In that case, there's no possible way to know the incoming type of that payload at compile-time; and it's likely that your user doesn't care, either - they just want to map some field, of a given type, in a JSON document, to something else.
If that sounds like a situation that you need to handle, well, congratulations: this package is for you!
Json.InElm works by lifting any valid JSON document into a type, Node, that defines:
node : Result Json.Decode.Error Json.InElm.Node
node =
Json.InElm.parseJsonString rawJwon
rawJson : String
rawJson =
"""
{
"name": "John",
"age": 33,
"address": {
"city": "Davison",
"country": "America"
},
"friends": [
{
"name": "Cakie",
"hobbies": [ "plants", "fitness" ]
},
{
"name": "Paulo",
"hobbies": [ "BMX", "having a really great dog" ]
}
]}
"""