fsprojects / FSharp.Data

F# Data: Library for Data Access
https://fsprojects.github.io/FSharp.Data
Other
816 stars 288 forks source link

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

Open piaste opened 2 years ago

piaste commented 2 years ago

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.