Skip to content

fix: preserve exact numbers in JSON tree view - #179

Merged
anurag629 merged 1 commit into
codercops:developfrom
kudala-bharani:fix/122-lossless-json-tree
Oct 15, 2026
Merged

anurag629 merged 1 commit into
codercops:developfrom
kudala-bharani:fix/122-lossless-json-tree

Conversation

@kudala-bharani

Copy link
Copy Markdown
Contributor

What and why

Closes #122.

Tree view now uses the existing lossless-json parser and displays LosslessNumber values as numeric leaves with their exact text. Large integers and long decimals keep the same digits as Code view instead of being rounded or shown as expandable objects.

The checks use instanceof LosslessNumber so an ordinary JSON object with a field named isLosslessNumber still renders as an object.

How I tested this

  • Added 14 tests that render the actual Tree view with react-dom/server: the issue's example, numeric roots, nested values, overflow/underflow, negative zero, trailing zeros, ordinary JSON values, collapsed containers, invalid JSON, and objects with number-like field names.
  • Undid the source fix and reran the regression tests: nine failed on the incorrect numeric output. Restoring the fix made them pass. The field-name collision test also failed against the initial implementation and passes with the instance check.
  • npm run lint passes with 13 existing warnings in unchanged files; all changed files pass with zero warnings.
  • npm run test: 251 tests pass.
  • npm run build: passes on Node 22, including TypeScript and page generation.
  • Checked the production build in Chromium in dark and light themes: formatted the issue's example, compared exact numeric text in Code and Tree views, checked nested/root values, and used Expand/Collapse and keyboard activation. No browser runtime errors in that run.

AI assistance

Used OpenAI Codex to implement the fix and regression tests, review the diff, and run the checks above.

Type of change

  • Bug fix
  • Tests

Checklist

  • I was assigned the linked issue
  • npm run lint && npm run test && npm run build passes locally
  • No analytics, trackers, or calls that send user data off-device
  • Works in both light and dark themes

Notes for reviewers

No new dependencies. TreeView is exported for the render tests, and Vitest gets the same @ alias the app already uses. Parsing stays in the component; no shared conversion logic changed.

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kudala-bharani, this does everything #122 asks. I merged it onto current develop: lint shows only the 13 old warnings, all 251 tests pass, and with the fix taken out 9 of the new tests fail. Rendering the real tree with react-dom/server is a nice way to cover this without a new dependency. Since the PR adds an @ alias to the vitest config, I'll update the line in CONTRIBUTING that says there isn't one. Merging.

That's your 5th merged PR this month, so you qualify for the CODERCOPS swag (our own program, separate from Hacktoberfest), which goes to the top 5 at the end of October. We DM the winners on Discord, so please join the server and run /link there to connect your GitHub. The invite is on https://oss.codercops.com/leaderboard/2026-10.

@anurag629 anurag629 added the hacktoberfest-accepted PR counts for Hacktoberfest label Oct 15, 2026
@anurag629
anurag629 merged commit 782b464 into codercops:develop Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberfest-accepted PR counts for Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep big numbers exact in the JSON formatter's Tree view

2 participants