2

In a case where I have a JSON input text editor and JSON Parser (eg: Jackson), how do I link between the location of where my cursor is to what path in the JSON I'm currently looking for? Something similar to how when editing a JSON file in VSCode, it is able to detect what your cursor is at in the outline. For example, with JSON:

{  
    "employee": {  
        "name":       "sonoo",   
        "salary":      56000,   
        "married":    true  
    }  
}

How do I retrieve what Line 3: Character 10 (the n in name) is pointing to in the JSON Object? Looking for libraries or implementations that may help.

euph
  • 21
  • 1
  • 1
    What are you trying to implement? A web app or a desktop application? – Simon Martinelli May 26 '21 at 13:56
  • May be useful: There is a nice [collection of JSON-Libraries on GitHub](https://github.com/burningtree/awesome-json) – gkhaos May 26 '21 at 14:21
  • @SimonMartinelli i'm planning to make a desktop application. a JavaFX (probably) text editor that shows the JSON path of where the cursor is at while editing (eg: if its at `employee->name` it'll show `employee.name` as a path) – euph May 26 '21 at 18:09
  • I am not sure why a discinction between Desktop or web app makes sense here. – Queeg May 26 '21 at 19:40
  • If you use a JSON parser in generic mode (where the JSON document would be parsed into generic Java Map and List types there is no such metainformation available. So you would have to use a parser supporting something like https://stackoverflow.com/questions/13796045/java-json-library-that-supports-dom-style-access – Queeg May 26 '21 at 19:42

0 Answers0