Preserve jsonb number representation in the JSON editor (#9854)#10074
Preserve jsonb number representation in the JSON editor (#9854)#10074dpage wants to merge 1 commit into
Conversation
…9854) The Query Tool's JSON cell editor pretty-printed jsonb values by parsing and re-stringifying them with json-bignumber. While that preserves big integers, it normalizes decimals through a JS float, so trailing fractional zeros are dropped (10.00 -> 10, 3.140 -> 3.14). Because the reformatted text is what gets written back, opening an unrelated jsonb document and saving it silently rewrote numbers it never edited - which can break applications that rely on the canonical jsonb text. Switch the editor to lossless-json, which preserves the exact numeric representation (big integers and trailing zeros alike), and pass it to the underlying vanilla-jsoneditor as its parser so the in-editor format action and tree/table modes are lossless too. The lossless helpers are centralized in a small json_utils module with unit tests. Closes pgadmin-org#9854
There was a problem hiding this comment.
Pull request overview
This PR fixes lossy round-tripping of jsonb values in the Query Tool JSON cell editor by switching the editor’s formatting/parsing to a lossless JSON implementation so numeric text (including trailing fractional zeros) is preserved when users open and save JSON without editing.
Changes:
- Introduce shared
json_utilshelpers backed bylossless-jsonto pretty-print JSON without normalizing numeric representations. - Update the Query Tool JSON editor to use the new lossless helpers and pass a lossless
parserthrough tovanilla-jsoneditor(covering text + tree/table modes). - Add Jest regression tests and document the fix in release notes.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| web/yarn.lock | Adds the lossless-json dependency to the lockfile. |
| web/package.json | Declares lossless-json as a web dependency. |
| web/regression/javascript/sqleditor/json_utils.spec.js | Adds regression coverage for trailing-zero preservation and parser interface. |
| web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/json_utils.js | Centralizes lossless parse/stringify + pretty-print helpers for the JSON editor. |
| web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/Editors.jsx | Switches JSON cell editor formatting to lossless helpers and wires the lossless parser into the editor. |
| web/pgadmin/static/js/components/JsonEditor.jsx | Uses the configured parser’s stringify when serializing non-text modes to avoid lossy JSON serialization. |
| docs/en_US/release_notes_9_16.rst | Notes the bug fix for jsonb trailing-zero preservation in the JSON editor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (6)
WalkthroughThe PR fixes JSON editor data corruption where trailing fractional zeros and large integer representations were lost during round-trip editing of jsonb values. A new ChangesJSON Number Preservation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
json-bignumber(JSONBigNumber.stringify(JSONBigNumber.parse(value), null, 2)). That preserves big integers but normalizes decimals through a JS float, so trailing fractional zeros are dropped (10.00→10,3.140→3.14).lossless-json(the maintained sibling ofjson-bignumber), which preserves the exact numeric representation — big integers and trailing zeros. It's also passed to the underlyingvanilla-jsoneditoras itsparser, so the in-editor Format action and tree/table modes are lossless too.json_utilsmodule with unit tests.Test plan
regression/javascript/sqleditor/json_utils.spec.js(5 tests) covering trailing-zero preservation, big integers, indentation, and the parser interface — all passing.eslint -c .eslintrc.jsclean on all changed files.SELECT '10.00'::jsonb; double-click the cell — the editor shows10.00(not10); save without editing — the stored value is unchanged.Closes #9854
Summary by CodeRabbit
Bug Fixes
10.00) were stripped and large integers in JSONB values were corrupted on save.Tests