Closed Bug 1847897 Opened 2 years ago Closed 1 year ago

JSON PrettyPrint feature is rounding large numbers

Categories

(DevTools :: JSON Viewer, defect, P2)

Firefox 136
Desktop
Windows 10
defect

Tracking

(firefox-esr128 unaffected, firefox134 unaffected, firefox135 unaffected, firefox136 fixed)

RESOLVED FIXED
136 Branch
Tracking Status
firefox-esr128 --- unaffected
firefox134 --- unaffected
firefox135 --- unaffected
firefox136 --- fixed

People

(Reporter: soehme, Assigned: nchevobbe)

References

(Regression)

Details

(Keywords: regression)

Attachments

(2 files)

Attached file test.json

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0

Steps to reproduce:

  1. Download attached file test.json (or create new in text editor and store somewhere). The content of the file is
    {"a":100000000000000001}
  2. In Firefox in new Tab hit CTRL+O
  3. In the dialog Browse the test.json and open it
  4. Click "Raw Data"
  5. Click "Pretty Print"

Actual results:

Output of the Pretty print is:
{
"a": 100000000000000000
}
The Number 100000000000000000 can also be seen in step 3. in the tree view

Expected results:

Pretty Print output should be:
{
"a": 100000000000000001
}
Also non-rounded number 100000000000000001 should be displayed in step 3. in tree view.

It is important to display values without modification and only change whitespace outside of strings when debugging APIs communicating with JSON format.

The Bugbug bot thinks this bug should belong to the 'Firefox::File Handling' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → File Handling
Component: File Handling → JSON Viewer
Product: Firefox → DevTools

thank you for reporting.
this comes from the limitation of JavaScript, which uses IEEE754 for numbers.
this is dupe of bug 1431808

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Duplicate of bug: 1431808
Resolution: --- → DUPLICATE

My bug was closed as duplicate of bug 1431808
bug 1431808 was fixed and I retested with latest nightly build 136.0a1 (2025-01-20) (64-Bit)

But the solution of bug 1431808 did not fix this, it made it worse. Now the Pretty print output (following same click instruction) is

{
"a": {
"source": "100000000000000001",
"parsedValue": 100000000000000000
}
}
and not the expected result from my original report.

There needs to be a seperate solution for this.

I am therefore resetting it back to UNCONFIRMED status.
Feel free to close it as duplicate of another bug if this is already known and a solution for the pretty print part already is in work.

Status: RESOLVED → UNCONFIRMED
No longer duplicate of bug: 1431808
OS: Unspecified → Windows 10
Hardware: Unspecified → Desktop
Resolution: DUPLICATE → ---
Version: Firefox 116 → Firefox 136

Thanks for checking, Bug 1431808 indeed made this worse but we should now be able to properly fix the initial issue.

Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: regression
Priority: -- → P2
Regressed by: 1431808

Could we do something like this instead:

a: 100000000000000000 [Raw: 100000000000000001]

Set release status flags based on info from the regressing bug 1431808

:nchevobbe, since you are the author of the regressor, bug 1431808, could you take a look?

For more information, please visit BugBot documentation.

(In reply to Tom Schuster from comment #5)

Could we do something like this instead:

a: 100000000000000000 [Raw: 100000000000000001]

I am not sure if I would like this solution.

My expectation with pretty print would be that it produces a valid JSON file that has identical content to the original file, only the (non-significant) whitespace is changed to make the file more readible.

The danger with the originally reported behaviour is that the file is changed but with bigger files than the simple test file, changes might go unnoticed by user (note: if the file is saved after pretty-print it saves the output of the pretty-print feature). With the proposed solution, user would definitely notice, but resulting file would not longer be valid JSON.

acceptable solutions could IMHO be:

  • simply use the raw value (as the expected behaviour I have written in original report)
  • same behaviour as originally reported, but display a clear warning that the resulting pretty-printed file is changed compared to original (so user should not use pretty print if they require unchanged file, for example when debugging JSON HTTP interface that is not JS based)
  • or let user decide if JS parsed or raw values should be used

Thanks for the report, I'm just going to fix the issue and properly display the raw value , we don't need to display the parsed value here IMO since it's already shown in the JSON tab

Flags: needinfo?(nchevobbe)

In Bug 1431808, we're handling those numbers in the tree,
which changes the data we're then using for pretty printing.
This patch handle those JSON_NUMBER using a replacer function
and JSON.rawJSON in the JSON.stringify call we're using.
This also allows us to handle -0.

Assignee: nobody → nchevobbe
Status: NEW → ASSIGNED
Pushed by nchevobbe@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/8066155efb5a [devtools] Fix JSON viewer pretty print for numbers whose source is different from JS parsed value. r=devtools-reviewers,jdescottes.
Status: ASSIGNED → RESOLVED
Closed: 2 years ago1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 136 Branch

rechecked with Firefox Nightly 136.0a1 (2025-01-26) (64-Bit) -> fixed as expected :)

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: