#How to properly set Erlang/OTP for gleam/json?

1 messages · Page 1 of 1 (latest)

cobalt thorn
#

Hi! I was trying to get started with Gleam, and decided to start my journey with (what I thought) a rather simple task. My goal was to decode a string JSON from another service, and for that I stumble upon the gleam/json package. I installed brew install gleam and added gleam add gleam_json, and then executed my code:

let assert Ok(data) = json.decode(from: body, using: dynamic.field("name", dynamic.string))

But I kept getting the same error:

Insufficient Erlang/OTP version.
`gleam_json` uses the Erlang `json` module introduced in Erlang/OTP 27.
You are using Erlang/OTP 26
Please upgrade your Erlang install or downgrade to `gleam_json` v1.0.1.

I completely ignored the v1.0.1 suggestion, because I didn't understand what was Erlang/OTP. After a quick read on the Erlang/OTP documentation and confirming that brew install gleam installs the erlang@26:

➜  ~ brew info erlang
==> erlang: stable 26.2.5 (bottled), HEAD

I decided to do it the hard way. Then I installed brew install kerl alongside with Erlang/OTP 27 and uninstall gleam, and compile gleam from the make install repository. After a couple of hours and reading, I managed to have everything sorted, but even after installing the version OTP 27.0 version I was still getting the same error message...
Finally decided to install the gleam_json = "1.0.1" and ... it worked! but then I got curios and read the source code for the Erlang FFI and I noticed:

decode(Json) ->
    thoas:decode(Json).

But I was expecting to use the newly JSON on the Erlang/OTP 27. After many other attempts, I changed the gleam_json dependency to >= 2.0.0 and to my surprise the error disappeared... I assume that this triggered something that updated something on gleam (cache, paths, ...)

It would really help to have a reference to kerl in gleam/json or asdf. And how to use a different Erlang version. I am still not sure if I did it correctly.

sick lake
#

If you want to use OTP <27 then use gleam_json 1.0.1

#

An error message in a library is not the place to document how to install a runtime

#

And I think it's reasonable to expect folks to know the name of the runtime they are using

#

Like it's normal for a npm package to talk about "supported node versions", etc

cobalt thorn
#

hey! thanks for the quick response. But that's the thing that got me thinking, I managed to get gleam_json v2.0.0 running with Erlang/OTP 27. After switching between 1.0.1 and 2.0.0, which the thing I still don't fully understand.
And, you are right about the runtime understanding. Maybe this is just my lack of context on the Erlang ecosystem on how to install different versions (kerl is amazing). Also it didn't helped that brew installs by default erlang@26 and there isn't any reference to erlang@27

sick lake
#

It's up to you how you want to install and manage software in the Erlang world as much as it would be in Python or Java

#

Some people use brew, some use kerl, some use asdf, some use docker, some use apt, etc

cobalt thorn
#

yes, makes sense. Any ideas on why is it possible to run Erlang/OTP 27 with gleam_json v2.0.0, after switching between v1.0.1 and v2.0.0? I feel that I am missing something here

sick lake
#

gleam_json v2 supports OTP27 and up

#

It doesn't support lower

cobalt thorn
#

right, I see it now. Sorry, I got confused with the /main branch and the v2.0.0 tag. thanks for the quick help!

cobalt thorn
sick lake
#

Thank you

#

It’s true, I do have a lot of Gleam experience