Skip to content

Preserve decimal formatting #2618

Description

@nickgeorge

Hello, I'm trying to use this as part of a specialized json parsing/printing library. It is essential that performing a round trip parse-print does not modify data. Therefore, internally, we store decimals as strings, guaranteeing that formatting is not destroyed. Is it possible to reproduce this in nlohmann/json? or is it inherently destructive?

Examples:

2.500 becomes 2.5
1E-22 becomes 1e-22
66.899999999999991 becomes 66.89999999999999

I understand the limitations of float representation - the hope is that it's possible to enable a mode/custom parsing that internally parses decimals into as strings, so as to side-step these limitations.

Most broadly, the question is if it's possible to get to a guarantee that (other than insignificant white-space)

json::parse(my_json_string).dumps() == my_json_string

Thanks,
Nick

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions