feat: copy the path of the selected node (#165, #23)#219
Open
simon-vincent wants to merge 1 commit into
Open
Conversation
…otdev#23) Adds a way to copy the path to the currently-selected JSON node, in two formats: - JSONPath: $.data[0]["user-name"] - JavaScript accessor: data[0]["user-name"] A clipboard button in the PathBar opens a small menu with both options, and a Shift+P shortcut copies the JSONPath form directly (mirroring the existing Shift+C 'copy selected node' shortcut). Path formatting lives in a pure, unit-tested utility (formatPath) that walks the JSONHeroPath components, using bracket notation for array indices and for keys that are not safe JS identifiers.
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
Adds the ability to copy the path of the currently-selected node, in two formats:
$.data[0]["user-name"]data[0]["user-name"]Two ways to use it:
Shift+Pkeyboard shortcut copies the JSONPath form of the selected node directly — mirroring the existingShift+C("copy selected node") shortcut.Closes #165 and #23 (both request this; #165 was prototyped in a fork by a user).
How it works
Path formatting lives in a pure, dependency-light utility,
app/utilities/pathFormatter.ts:formatPath(path: string, format: "jsonpath" | "js"): stringIt walks the
JSONHeroPathcomponents and:[0]),user-name, keys with spaces/quotes), escaping embedded quotes/backslashes.Root selection →
$(JSONPath) /""(JS). No new dependencies — reuses the existingUI/Popoverwrapper,react-hotkeys-hook, and@jsonhero/path.Tests
tests/pathFormatter.test.ts— 12 unit tests covering nested keys, array indices, unsafe/hyphenated keys, quote escaping, leading-index, and the root case. Written test-first.npm test),npm run build✅.data[0]["user-name"]and using both menu items andShift+Pproduced the expected strings.Notes
npm run buildandnpm testboth pass on this branch. The onlytscerror is a pre-existing dangling import onmain(HomeTriggerDevBannerinapp/routes/index.tsx), unrelated to this change — fixed separately in fix: remove dead HomeTriggerDevBanner import that breaks the lint gate #218.