josdejong / jsoneditor

A web-based tool to view, edit, format, and validate JSON
http://jsoneditoronline.org
Apache License 2.0
11.62k stars 2.04k forks source link

Select and lookup JSONPath #168

Open PanderMusubi opened 9 years ago

PanderMusubi commented 9 years ago

Please support lookup of JSONPath for where the cursor is. Additionally, select (of highlight) JSON for a specified JSONPath.

josdejong commented 9 years ago

Interesting idea. I suppose this will be useful in combination with an event listener focus, which is fired every time the focus has moved to an other element.

luxlux commented 9 years ago

To lookup a JSONPath is also the feature, which i wanted to request. It would be very helpful.

tomkcey commented 5 years ago

Interesting, so where would I start to implement this kind of feature. Any file in particular I should refer to?

PanderMusubi commented 5 years ago

I have only experience in Python and Java with this. A search like https://duckduckgo.com/?q=javascript+json+path comes up with already a few good ways.

josdejong commented 5 years ago

Thanks @tomkcey for your offer!

I guess this issue is about two features:

  1. Be able to copy the jsonpath of node, probably via a new action menu "Copy jsonpath", or via a new button in the navigation path right below the main menu (or both). For a given node, you can get the current path via node.getPath(), and convert it to a jsonpath using util.stringifyPath.
  2. Via the API, be able to select and focus a certain node. You can use node.scrollTo and after that node.focus, something like:
    node.scrollTo(function () {
      node.focus();
    });

    So I think we have to expose this as a new method editor.focus(jsonpath), which parses the path using util.parsePath, then finds the corresponding node using editor.node.findNodeByPath(...).

Does that make sense?

tomkcey commented 5 years ago

It does, but as I alluded to in the other issue's reply, I might have found a solution already for my limited needs. In fact, if my modifications in your source code don't break anything, it was only a matter of passing two parameters further down the onChange or onAction scopes. I'll get back to you in the coming weeks, then you can review my modifications and see if you can implement them in the code.

josdejong commented 5 years ago

:+1:

vasilvalkov commented 5 years ago

I see that editor.focus(jsonpath) is considered to be implemented. Is there any progress on it?

In my project I use external json validation which returns a json path when it finds an error and I need to set focus and highlight the erroneous node in the jsoneditor using this path.

josdejong commented 5 years ago

I haven't heard back from Thomas about it. @tomkcey is implementing this feature still on your radar?

PanderMusubi commented 5 years ago

Hope to see this implemented. Some ideas: Perhaps under or over both views an input field for entering a path and with enter the results are highlighted. A button next to this field called "copy from selection" would copy paste the path from the selected element of that view in the field.