Generates Elm code from a JSON sample in JsonString
config = [ JsonToElm.rule ]
The fix runs on top-level values with a JsonString type annotation. It generates JSON decoders and encoders as well as the necessary types and type aliases.
import Json.Decode import Json.Encode sample : JsonString sample = """@json{"a": 1}"""
import Json.Decode import Json.Encode type alias Sample = { a : Int } sampleDecoder : Json.Decode.Decoder Sample sampleDecoder = Json.Decode.map Sample (Json.Decode.field "a" Json.Decode.int) encodedSample : Sample -> Json.Encode.Value encodedSample sample = Json.Encode.object [ ( "a", Json.Encode.int sample.a ) ]
Note that the imports in the module are examined to determine the style of decoders.
If a Json.Decode.Extra import is present, then applicative-style decoders using Json.Decode.Extra.andMap will be generated.
Json.Decode.Extra
Json.Decode.Extra.andMap
If a Json.Decode.Pipeline import is present, then pipeline decoders are generated.
Json.Decode.Pipeline
You can try this rule out by running the following command:
elm-review --template alexkorban/elm-review-json-to-elm/example --rules JsonToElm
Generates Elm code from a JSON sample in JsonString
Before fix
The fix runs on top-level values with a JsonString type annotation. It generates JSON decoders and encoders as well as the necessary types and type aliases.
After fix
Note that the imports in the module are examined to determine the style of decoders.
If a
Json.Decode.Extraimport is present, then applicative-style decoders usingJson.Decode.Extra.andMapwill be generated.If a
Json.Decode.Pipelineimport is present, then pipeline decoders are generated.Try it out
You can try this rule out by running the following command: