Skip to content

.NET number values such as positive and negative infinity cannot be written as valid JSON. #48926

Closed

Description

@rodion-m

In .NET 5 double.NaN is written to json as "NaN". Why not to write double.PositiveInfinity and double.NegativeInfinity as "PINF" and "NINF"? And the same for float.

It's not good that Infinity values throw an exception (.NET number values such as positive and negative infinity cannot be written as valid JSON.).

Activity

  1. ghost added
    untriaged
    on Mar 1, 2021
  2. Tornhoof commented on Mar 1, 2021

    @Tornhoof
    Contributor
  3. rodion-m commented on Mar 1, 2021

    @rodion-m
    Author

    @Tornhoof AllowNamedFloatingPointLiterals solved the problem, thanks a lot! The developers should add this info into the exception text.
    Something like:

    .NET number values such as positive and negative infinity cannot be written as valid JSON. Consider JsonNumberHandling.AllowNamedFloatingPointLiterals to make it work.
    
  4. added
    documentation
    and removed
    untriaged
    on Mar 2, 2021
  5. eiriktsarpalis commented on Mar 2, 2021

    @eiriktsarpalis
    Member

    The developers should add this info into the exception text. Something like:

    .NET number values such as positive and negative infinity cannot be written as valid JSON. Consider JsonNumberHandling.AllowNamedFloatingPointLiterals to make it work.

    I think this is a clarification that might make sense to incorporate in the exception message (with strong wording indicating that this will generate json incompatible with many applications). @layomia thoughts? @GrabYourPitchforks might be opinionated on this as well.

  6. added this to the Future milestone on Mar 2, 2021
  7. GrabYourPitchforks commented on Mar 2, 2021

    @GrabYourPitchforks
    Member

    Any exception text that helps developers better accomplish their task is goodness. :)

    The trick is that the exception text shouldn't say "do xyz" unless xyz is undoubtedly the right thing to do. If there's any nuance involved (e.g., "you can do this, but you need to be aware that it will create non-interoperable JSON") then it's often best to provide a link to a page that better explains all the scenarios.

  8. added
    help wanted
    good first issue
    on Oct 21, 2021
  9. deeprobin commented on Nov 18, 2021

    @deeprobin
    Contributor

    If you want you can assign me :)

  10. layomia commented on Nov 18, 2021

    @layomia
    Contributor

    @deeprobin sure. Note that this task involves updating the JsonNumberHandling.WriteAsString/AllowNamedFloating point API documentation as pointed out in #48926 (comment), and also manually updating the corresponding entries in the dotnet/dotnet-api-docs repo (via a separate PR in that repo). Then, the augmented exception message should link to the JsonNumberHandling documentation on the docs website.

  11. deeprobin commented on Feb 13, 2022

    @deeprobin
    Contributor

    I think this can be closed (PRs merged)
    /cc @layomia

  12. rodion-m commented on Feb 13, 2022

    @rodion-m
    Author

    I think this can be closed (PRs merged) /cc @layomia

    Thanks a lot!

  13. ghost locked as resolved and limited conversation to collaborators on Mar 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.Text.Jsondocumentationgood first issuehelp wanted

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions