Stream: beginners

Topic: JSON parsing?


view this post on Zulip Aurélien Geron (Jul 05 2026 at 20:15):

What's the plan for JSON encoding/decoding? Will this be part of the standard library or should users import https://github.com/lukewilliamboswell/roc-json ? If it's the latter option, is someone working on migrating it?

view this post on Zulip Niclas Ahden (Jul 05 2026 at 20:17):

Check out the built-in Json.parse. Mr. Json "Luke" Boswell brought it to my attention :ok:

view this post on Zulip Niclas Ahden (Jul 05 2026 at 20:22):

Note that there's currently a leak on successful parses (https://github.com/roc-lang/roc/issues/9953), but I don't think that'd be an issue for most use-cases. Given the perf of the Roc org I also think that'll be resolved swiftly ;D

view this post on Zulip Aurélien Geron (Jul 05 2026 at 20:26):

Oh wow, it works, so cool! :tada:

» numbers : Try(List(U64), _)
» numbers = Json.parse("[1,2,3]")
assigned `numbers`
» numbers
Ok([1, 2, 3])

view this post on Zulip Niclas Ahden (Jul 05 2026 at 20:27):

Indeed, lovin' it! Roc is really the best.

view this post on Zulip Aurélien Geron (Jul 05 2026 at 21:13):

I can encode a few things to JSON, but not everything. What am I doing wrong?

» Json.encode(123)
Ok("123.0")
» Json.encode(123.U8)
Ok("123")
» Json.encode("Hello, World!")
Ok("\"Hello, World!\"")
» Json.encode(Bool.True)
Ok("true")
» Json.encode([1, 2, 3])  # Error! Missing method.
» Json.encode({name: "Bob", age: 20})  # Error! Missing method.
» Json.encode(None)  # Error! Missing method.

view this post on Zulip Richard Feldman (Jul 05 2026 at 21:35):

oh I know what that is. Can you open an issue for it?

view this post on Zulip Luke Boswell (Jul 06 2026 at 06:13):

Updated the http package today and there's a demo in there with the new syntax which I think is pretty cool :smile:

https://github.com/roc-lang/http/blob/main/examples/router.roc

view this post on Zulip Luke Boswell (Jul 06 2026 at 06:16):

I suspect there will be a more idiomatic way to setup CRUD style API's but the Json parsing/encoding machinery is all there.

Like I wonder if it will be more idiomatic to have a Thing as a nominal type and then inside that have a DTO style inner record and then the parser and encoding methods use that so it's all contained in a nice abstraction (probably also in a separate file for just that type module).

view this post on Zulip Aurélien Geron (Jul 06 2026 at 07:46):

Richard Feldman said:

oh I know what that is. Can you open an issue for it?

Thanks @Richard Feldman , I opened https://github.com/roc-lang/roc/issues/9970

view this post on Zulip Richard Feldman (Jul 06 2026 at 11:46):

@Aurélien Geron ok, fixed! also I renamed Json.encode to:

I know a lot of JSON serialization libraries silently encode nan/infinity/-infinity as null, but I don't want to do that as a silent default. If there's demand for it, we can always introduce an explicit convenience function that you can opt into which does that.


Last updated: Jul 23 2026 at 13:15 UTC