JSPM

json-cursor-path

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q42391F
  • License MIT

Convert a position in a raw JSON to the path in the parsed object

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

  1. Install json-cursor-path

    npm i --save json-cursor-path
  2. Import JsonCursorPath using ES import

    import { JsonCursorPath } from "json-cursor-path";
  3. Create an instance representing a JSON file

    const cursorPath = new JsonCursorPath(`{\n  "key": ["val1", "val2"]\n}`);
  4. 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)