Yes, type is a reserved keyword and cannot be used as the name of a field in a record.
In Elm and Haskell, the most common task in your case is to add a single quote, so it becomes type' , and your type definition becomes
type alias Foo = { id: String , type': String }
This comes from the main character from mathematics. It may look odd at first, but it's syntax.
Then you can use the following Json Decoder to translate JSON to Foo:
fooDecoder = Json.object2 Foo ("id" := Json.string) ("type" := Json.string)
Note that the exact field name in Elm must not match the name of the JSON field.
You rarely find a language that allows you to use keywords as variable names without saving. This behavior is not unique to Elm.
source share