Skip to content

Preserve jsonb number representation in the JSON editor (#9854)#10074

Open
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:worktree-fix-issue-9854-jsonb-trailing-zeros
Open

Preserve jsonb number representation in the JSON editor (#9854)#10074
dpage wants to merge 1 commit into
pgadmin-org:masterfrom
dpage:worktree-fix-issue-9854-jsonb-trailing-zeros

Conversation

@dpage

@dpage dpage commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • The Query Tool's JSON cell editor pretty-printed jsonb values by round-tripping them through 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.0010, 3.1403.14).
  • Because the reformatted text is what gets written back on save, opening an unrelated jsonb document and saving it silently rewrote numbers the user never edited — corrupting data for applications that depend on the canonical jsonb text. (The data-grid cell itself renders the raw value correctly; only the editor reformats lossily.)
  • Fix: switch the editor to lossless-json (the maintained sibling of json-bignumber), which preserves the exact numeric representation — big integers and trailing zeros. It's also passed 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.

Test plan

  • New Jest spec 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.js clean on all changed files.
  • Manual: in the Query Tool, SELECT '10.00'::jsonb; double-click the cell — the editor shows 10.00 (not 10); save without editing — the stored value is unchanged.

Closes #9854

Summary by CodeRabbit

  • Bug Fixes

    • Resolved JSON editor issues where trailing fractional zeros in numbers (e.g., 10.00) were stripped and large integers in JSONB values were corrupted on save.
  • Tests

    • Added tests to verify proper JSON number handling and formatting preservation.

…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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_utils helpers backed by lossless-json to pretty-print JSON without normalizing numeric representations.
  • Update the Query Tool JSON editor to use the new lossless helpers and pass a lossless parser through to vanilla-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.

@dpage

dpage commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 411ad779-937b-460c-8936-5e83acb54af1

📥 Commits

Reviewing files that changed from the base of the PR and between 04fa05c and 5b500bf.

⛔ Files ignored due to path filters (1)
  • web/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (6)
  • docs/en_US/release_notes_9_16.rst
  • web/package.json
  • web/pgadmin/static/js/components/JsonEditor.jsx
  • web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/Editors.jsx
  • web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/json_utils.js
  • web/regression/javascript/sqleditor/json_utils.spec.js

Walkthrough

The 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 lossless-json dependency and utility module preserve numeric formatting through serialization, integrated into the generic JsonEditor component and SQL editor's data grid.

Changes

JSON Number Preservation

Layer / File(s) Summary
Lossless JSON utility module and dependency
web/package.json, web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/json_utils.js, web/regression/javascript/sqleditor/json_utils.spec.js
Adds lossless-json ^4.3.0 dependency and creates utility module exporting losslessJSONParser, prettifyJSONString, and prettifyJSONValue. Tests validate round-trip preservation of trailing zeros and big-integer handling across serialization cycles.
Generic JsonEditor component serialization
web/pgadmin/static/js/components/JsonEditor.jsx
Updates onChange handler to use configurable options.parser (defaulting to JSON) for serializing non-text editor content, enabling consumers to inject lossless serialization while maintaining backward compatibility.
SQL Editor QueryToolDataGrid integration
web/pgadmin/tools/sqleditor/static/js/components/QueryToolDataGrid/Editors.jsx
Imports lossless utilities and updates JsonTextEditor memoized value transformation for jsonb and array types to use prettifyJSONString and prettifyJSONValue instead of JSONBigNumber logic. Configures JsonEditor with losslessJSONParser to preserve numeric formatting end-to-end through editing and saving.
Release notes documentation
docs/en_US/release_notes_9_16.rst
Documents fix for Issue #9854, noting that JSON editor no longer strips trailing zeros or rewrites large integers in jsonb values during save operations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: preserving jsonb number representation in the JSON editor, directly matching the core objective.
Linked Issues check ✅ Passed All requirements from issue #9854 are met: trailing zeros are preserved via lossless-json library, the JSON editor displays and saves values without modification, and unit tests validate the fix.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing jsonb number preservation: dependency addition, JSON editor updates, utility module creation, release notes, and comprehensive test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pgadmin doesn't preserve trailing zeros in jsonb

2 participants