lukewilliamboswell / roc-json

Json package for Roc
https://lukewilliamboswell.github.io/roc-json/
Universal Permissive License v1.0
21 stars 13 forks source link

Decoding from UTF8 #27

Open normanjaeckel opened 5 months ago

normanjaeckel commented 5 months ago

I ran into some issues while decoding some JSON with German letters like ö. I want to understand how this package work and I found this line.

I think the test is wrong (and then also the implementation): The correct decoding of (i. e. \u2c64) is [226, 177, 164] and not [44, 100] as the test says. In my case I want to decode \u00f6 which should be ö, but the parser just fails.

Maybe you want to test this as follows (I can not run the test according to #24 at the moment):

expect
    bytes = "\"\u00f6\"" |> Str.toUtf8
    decoded = Decode.fromBytes bytes json
    decoded == Ok "ö"

Thank you very much in advance.

normanjaeckel commented 4 months ago

My current workaround is that I copied some code from https://github.com/roc-lang/unicode to fix the wrong hexToUtf8 function in https://github.com/lukewilliamboswell/roc-json/blob/main/package/Json.roc#L1139. Should I make a pull request or do you prefer using the unicode lib in this case?

lukewilliamboswell commented 4 months ago

A PR would be great thank you for looking into this.