Tarmil / FSharp.SystemTextJson

System.Text.Json extensions for F# types
MIT License
329 stars 45 forks source link

String-keyed Map output like as Dictionary #82

Closed akhansari closed 3 years ago

akhansari commented 3 years ago

I wonder why they haven't the same output. Just curious what's the reason behind this?

Is there any possibility to have the same, Map like Dictionary?

Tarmil commented 3 years ago

The output should be a JSON object in both cases. The only difference is the order of the keys: Map is sorted by comparing the keys, whereas Dictionary is sorted in an arbitrary order that is based on its internal implementation.

JsonSerializer.Serialize(Map ["b", 1; "a", 2], options) // --> {"a":2,"b":1}
JsonSerializer.Serialize(dict ["b", 1; "a", 2], options) // --> {"b":1,"a":2}

Is this what you mean? Or do you have other differences?

akhansari commented 3 years ago

Thanks Tarmil for the explanation.. My bad, it's only non string-keyed Map that is serialized to an array of arrays. It's perfect because we can have interoperability between other dictionary types and F# string-keyed Map.