Serialising a value of type Map<string,'T> adds quotes around string values. E.g.,
(Map.ofList ["foo", 1] |> toJson) = """{"\"foo\"" : 1}"""" // evaluates to true
(Note that the key is serialised not as the string foo but as the string "foo".)
Compile the following; the console will show the actual and expected serialisation.
#r "node_modules/fable-core/Fable.Core.dll"
open Fable.Core
open Fable.Core.JsInterop
let v = [ "foo", 1 ] |> Map.ofList
let serialised = toJson v
let expected = """{"foo":1}"""
if expected <> serialised then
printfn "Unexpected deserialisation."
printfn "value (%%A): %A" v
printfn "serialisation: %s" serialised
printfn "expected: %s" expected
Expected: no output.
Actual output:
Unexpected deserialisation.
value (%A): [["foo",1]]
serialisation: {"\"foo\"":1}
expected: {"foo": 1}
Thanks for reporting this. I guess this is because you can have any object as map key, so the keys are being serialized to string as well, including string keys. In actuality, it's working as is, but I agree is nicer to have the strings without quotes, so I'll try to check if the keys are string first :+1:
Thanks!
I wouldn't say its working, though: If I round-trip a Map<string,'T> from server to client to server, the keys have quotes on them when they get back. That means that Map.find "foo" m works before the round-trip, but breaks afterwards.
Btw, thanks for an exciting compiler/framework!
You're right. It was an easy fix anyways, can you try with latest fable-core version?
Works as expected, both in the small example above and in my larger prototype app. Thanks a bunch!