svelte-jsoneditor
svelte-jsoneditor copied to clipboard
Allow copy node's path
Could be copy on ContextMenu or emit on
mousedown
.
Thanks, good suggestion. I think this should be an explicit button in the ContextMenu, and possibly also a quick key.
@josdejong how about copy JSONPath
instead of or over slice?
Good point about what format to use: JSONPath, JSONPointer, JavaScript notation...
An other idea: I also want to implement a path (like "bread crumbs" on top, like in the old editor:
We could also make the copy button there.
Another idea it would be nice if you could paste a path too, and then scroll towards this path in the document.
vote up for copy node path button near the breadcrumbs. Very handy and easy to implement :+1:
Hi, I had to recently work around this issue by getting the path from a selected node through onChange (patchResult.from) function then reverting the changes in the document - basically making the doc readOnly but keeping the editable state in order to get the currently selected path. This fix to the API would be really helpful, as the info is already on hand... The path should be available on the API onClick or something similar...
I'm working on this feature right now.
I was wondering: what kind of path notation do you guys use? A JSON Path like $.data[2].nested.property
, or a JSON Pointer like /data/2/nested/property
?
@josdejong thanks a lot! I guess any will be fine if we can easily parse, split, modify it as we want. Some kind of trigger (onNodePathCopy) will be cool.
personally I like the first one $.data[2].nested.property
as default
Yes I prefer a notation like $.data[2].nested.property
better too. I'll start with that.
What would be the use case for a onNodePathCopy
callback?
@josdejong it would let anyone to parse and copy node path in the way one wants, not only as default $.data[2].nested.property
format. Just an idea.
Yes, that makes sense. I have a PR #164 ready. I have implemented a new option pathParser: { parse, stringify }
, allowing you to customize how the path is parsed/stringified. By default it uses a JSON Path notation, but you can configure it to use JSON Pointer instead or anything you want.
First version now published in v0.7.10
.
Feedback is very welcome, I can imagine there are good ideas to refine this solution further.
What would be the use case for a
onNodePathCopy
callback?
It would be nice to have the JSON path value through the API - on the current selected node, not just after a copy.
This would basically be the same info that is displayed in the navigation bar, but in the API.
How could I achieve this?
I imagine it would be part of the exposed object jsonEditor - which there is a ref to...
@feidhlimx there are plans to implement an API to get and set the selection, see #163. I think that will address your suggestion.