NPP-JSONViewer / JSON-Viewer

A JSON viewer plugin for Notepad++. Displays the selected JSON string in a tree view.
MIT License
754 stars 150 forks source link

Pretty print can corrupt the data (lost precision on numbers) #196

Open Nezrahm opened 2 months ago

Nezrahm commented 2 months ago

Let's take this simplified json as an example {"MyDecimal":5.107091491635510056019771245}

If I format/pretty print this data then will the result be

image

This has effectively corrupted the data.

SinghRajenM commented 2 months ago

Duplicate of #39

molsonkiko commented 2 weeks ago

The number described in this original issue has higher precision than the maximum precision for a double (so some loss of precision is literally inevitable), but here are some numbers where JSON-Viewer loses precision unnecessarily (i.e., a better double-formatting algorithm could retain that precision):

[
    -5.0975200963490517E-33,
    -6.3809366960906694E-48,
    -7.4034655373995265E-78,
    -7.7377839245507245E-78,
    1.2859736125485259E-22,
    -3.5403485244736897E-88,
    -6553693.3617752995,
    -6.8141086401061905E-44,
    5.5843284390697506E-71,
    -4.3180528943019356E-77,
    -5.8231387142089446E-34,
    4.9686769279508796E-34,
    -1.7271559814272259E-77,
    -4.2596088775464085E-81,
    3.7049941506206046E-71,
    3.9742364030067576E-86,
    3.1628542535929037E-89,
    -268.52143589416397,
    -2.2795405986944148E-93,
    -7.3921473885461993E-95,
    -5.1970028999668327E-45,
    3.5937267475433058E-09,
    7.2781313854297585E-75,
    2.1823857766614118E-78,
    8.9080568887277594E-11,
    -898453.63759556494,
    -6.5029793100887976E-55,
    15650583.101212589,
    -7.7306921203660293E-55,
    4.3436060211811726E-74,
    -7.1399486851522386E-90
]

The most recent version of JsonTools can reformat this file without losing precision on any of these numbers.