I want to check if anything is lost when I go json -> decoder -> to_json, so far the only way I could think of is do json -> decoder -> to_json then check if roundtrip json decode dynamic is the same as original json decode dynamic. However in some cases it might be ok for items in the json to change order, but that makes comparing the old/roundtrip dynamic fail even if (I believe) they are otherwise the same. Is there a nicer way to confirm that nothing changed in the json besides order of items?
pub fn check_roundtrip(
in: String,
thing_dec: decode.Decoder(a),
thing_to_json,
from_test: String,
) {
let assert Ok(as_dynamic) = json.parse(in, decode.dynamic)
as { from_test <> " check_roundtrip decode dynamic" }
let assert Ok(as_thing) = json.parse(in, thing_dec)
as { from_test <> " check_roundtrip decode thing" }
let assert Ok(as_dynamic_roundtrip) =
as_thing
|> thing_to_json
|> json.to_string
|> json.parse(decode.dynamic)
assert as_dynamic == as_dynamic_roundtrip
as { from_test <> " check_roundtrip decode + encode roundtrip" }
}