FSharp.Data icon indicating copy to clipboard operation
FSharp.Data copied to clipboard

Boolean inference from 'yes'/'no' in JSON breaks roundtrip

Open piaste opened this issue 4 years ago • 0 comments

The JSON Provider, iirc like others, infers a boolean data type from yes or no strings (case insensitive).

However, the boolean representation as a yes/no string is not preserved, and generating a new JSON string via .ToString() will contain a JSON true/false field, which won't typically be compatible with the original JSON payload.

Repro script:


#r "nuget: fsharp.data"
open FSharp.Data

type Yes = JsonProvider<""" { "Foo" : "Yes" } """>
let yes = Yes.Root(foo = true)
printfn "%O" yes

(*
{
  "Foo": true
}
*)

Workaround : Use the InferTypesFromValues = false parameter and disable type inference entirely.

piaste avatar Dec 23 '21 17:12 piaste