Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
piaste opened this issue Dec 23, 2021 · 0 comments
Open

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

piaste opened this issue Dec 23, 2021 · 0 comments

Comments

@piaste
Copy link
Contributor

piaste commented Dec 23, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant