Map JSON-pointer to the {line, column} in a text JSON file

2.8k Views Asked by At

I need to map a location in JSON (or JavaScript object) defined by JSON-pointer to the position in JSON text file as {line,column}. Is there any existing JavaScript library that would do it? Writing this code is going to be a bit tedious...

For example, if I have a JSON file (text):

{
  "foo": [
    {
      "bar": 1
    }
  ]
}

then given JSON-pointer /foo/0/bar I need to get {line: 4, column: 7} as the result.

If an equivalent JSON value is stored in this JSON file:

{"foo":[{"bar":1}]}

then the result for the same JSON pointer should be {line: 1, column: 10}.

1

There are 1 best solutions below

0
On BEST ANSWER

This library has the equivalents of JSON.parse/stringify that also return mappings: https://github.com/epoberezkin/json-source-map