I've submitted #5488 to remove Json from builtins. The plan is to break the overall change over a few PRs, so that they are a more manageable changes. This is Part 1 which essentially just renames Json to something that people won't accidentally use, but should still keep everything working as before.
If anyone would like to use Json I have created a package at lukewilliamboswell/roc-json which is a copy of the old Json module. I'm still working on improving Json, adding tests and features, and removing it from the builtins will also make this easier. (For a start I can use the name Json
and break it into multiple files to improve docs and hide internal details).
love the approach, this is awesome!!!
I think I am stuck on the changes for Part 2. I've pushed where I am up to in this PR #5543. My rust isn't great, so looking for some assistance on how to include the ExampleJson.roc
file as a string inline in these tests. For example in mono tests I think I need to do something around roc_load::load_and_monomorphize_from_str
in crates/compiler/test_mono/src/tests.rs
but not really sure how to do this.
I've started with trying to get mono tests working, the rust compiles, but then tests fail at load_and_monomorphize_from_str
with a LoadMonomorphizedError
and hit a panic.
The macro to do that in Rust is include_bytes!
. We already use it in a few places (I used it in the web REPL), so you can search for examples. You get a constant slice of u8, which is probably what you want.
there is also include_str!
which may be useful if you really need a string
I've had another go at this, my idea was to include the json code by concatenating the implementation with the test. I removed the interface module header, so I feel like that should be ok. However it compiles and runs, but the test is always 'FAILED' and I'm not sure if there is any way to get additional debugging. The test 'PASSED' with the same implementation when the ExampleJson (currently name TotallyNotJson) interface module was imported as a builtin, so I think there must be something about the rust test here that is causing this issue.
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn decode_use_stdlib() {
let test_code = indoc!(
r#"
app "test"
imports []
provides [main] to "./platform"
MyNum := U8 has [Decoding {decoder: myDecoder}]
myDecoder =
Decode.custom \bytes, fmt ->
when Decode.decodeWith bytes Decode.u8 fmt is
{result, rest} ->
when result is
Ok n -> {result: Ok (@MyNum n), rest}
Err e -> {result: Err e, rest}
main =
when Decode.fromBytes [49, 53] json is
Ok (@MyNum n) -> n
_ -> 101
"#
);
assert_evals_to!(
&format!("{}{}", test_code, include_str!("ExampleJson.roc")),
15,
u8
)
}
do you have a branch for this?
@Ayaz Hafiz it's https://github.com/roc-lang/roc/pull/5543
Last updated: Jul 06 2025 at 12:14 UTC