Pretty-print JSON cells by default without marking them changed#1412
Merged
Conversation
…r tree-sitter-json grammar
…low on deeply nested input
…nstead of a popover" This reverts commit 2b25cb6.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
JSON and JSONB cells now display pretty-printed by default in every viewer (inline sidebar cards, expanded sidebar, cell popover, pop-out window), in both read-only and editable modes. Viewing or reformatting a value no longer marks the row as changed. Original key order and exact number values are preserved everywhere, including the Tree view and on save.
From user feedback: the old "Format JSON" button reformatted by rewriting the cell value, which marked the row dirty, and the formatter sorted keys and rounded large integers. For an event store that is JSONB everywhere, that made the everyday "just let me read this" action destructive.
Root cause
Four faults combined:
JSONSerializationwith.sortedKeys, which reorders keys and coerces numbers throughNSNumber, losing precision above 2^53 (snowflake / bigint IDs)..sortedKeys, reordering keys on every save.Changes
JsonSyntaxParser+JsonReindenter: a scalar-level parser and formatter that copies keys, number tokens, and string contents byte for byte. Preserves key order and exact numbers, handles top-level primitives, passes invalid JSON through unchanged, capped at 500 KB.JSONViewerViewnow holds adisplayTextbuffer that is pretty in both modes. Removed the{}Format button (the view opens pre-formatted). Save stores the normalized, order- and precision-preserving form.MultiRowEditState.updateFieldcompares JSON fields semantically (normalize(new) == normalize(original)), so a pure reformat is never a change. Added a cachedisJsonflag, also true for text columns whose value looks like JSON.JSONSyntaxTextViewread-only viewer gains the find bar (Cmd+F) and plain-text mode.Tests
JsonReindenterTests: key order, large-integer and decimal precision, top-level primitives, invalid passthrough, idempotence, normalize equivalence, escape and surrogate-pair decoding, size cap.MultiRowEditStateJsonTests: reformat is not a change, key reorder is a change, normalized storage, revert clears the change, large integers preserved, text column holding JSON, non-JSON exact comparison.StringJsonTests: updated for key-order preservation and the": "separator (the prior sorted-keys behavior is intentionally dropped).Docs
docs/features/json-viewer.mdxand added a CHANGELOG entry under Added.