Deprecated in favour of Chiron
Nice F# support for Newtonsoft.JSON - tuples as arrays, maps as objects, lists as arrays, unions as _name-metadata annotated arrays, decimals as strings to save precision, options as null/value, string-GUIDs and finally BigInt support.
Sponsored by qvitoo โ A.I. bookkeeping.
You have three choices;
open Newtonsoft.Json.FSharp
let str = JsonConvert.Serialize(o, [| GuidConverter() :> JsonConverter |])
open Newtonsoft.Json.FSharp
let str = JsonConvert.Serialize(o, Serialisation.converters)
This is a nice way to do it, because you can then pass those settings into your Bootstrapper/Composition Root of your program. Remember you need to acutally use the settings.
open Newtonsoft.Json.FSharp
let opts = Serialisation.extend (JsonSerializerSettings()) // this goes global
let str = JsonConvert.Serialize(o, opts) // this is local
You can find all the converters in the source tree.
The convert both from and to.
267321267876321I
=> {
"_name": "System.Numeric.BigInt, System.Numeric"
"value": "267321267876321"
}
CultureInfo "sv-SE"
=> "sv-SE"
Guid.NewGuid()
=> "6ac5c744-ad0b-412c-bf11-9fb732344d90"
[ 2;3;4;5 ]
=> [ 2,3,4,5 ]
[ "hello", "world"; "you", "there" ] => { "hello": "world", "you": "there" }
type A = { a : string; b : int option }
{ a = "hi"; b = None }
=> { "a": "hi", "b": null }
{ a = "hi"; b = Some 5 }
=> { "a": "hi", "b": 5 }
"3", 4e11
=> [ "3", 4e11 ]
type Drinks =
| Swimmingpool
| IrishCoffee of teaSpoonsSugar:int
Swimmingpool
=> {
"_name": "Drinks|Swimmingpool",
"value": null
}
IrishCoffee 3
=> {
"_name": "Drinks|IrishCoffee",
"value": [ 3 ]
}
Uri "http://haf.se"
=> "http://haf.se"