Skip to content

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

@piaste

Description

@piaste

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions