Package Exports
- json-cursor-path
Readme
json-cursor-path
Library to convert a cursor position in a JSON file to the path in the parsed JSON object.
Getting started
Install
json-cursor-pathnpm i --save json-cursor-path
Import JsonCursorPath using ES import
import { JsonCursorPath } from "json-cursor-path";
Create an instance representing a JSON file
const cursorPath = new JsonCursorPath(`{\n "key": ["val1", "val2"]\n}`);
Get the path corresponding to a cursor position
console.log(cursorPath.get(15)); // Output: "$.key[0]" console.log(cursorPath.get(15, true)); // Output: ["key", 0]
Performance
O(n) (cost of traversing the JSON until the specified cursor)