]> git.eshelyaron.com Git - emacs.git/commit
Add support for retrieving paths to JSON elements
authorSimen Heggestøyl <simenheg@gmail.com>
Sun, 8 Nov 2015 20:44:21 +0000 (21:44 +0100)
committerSimen Heggestøyl <simenheg@gmail.com>
Sun, 8 Nov 2015 20:44:21 +0000 (21:44 +0100)
commit29d740aac9773334d8189a1cc989634a48a70061
treeba5f1cbec0b0b413570cdfed8fd9fd5e19bda6e6
parent5193ad1bcbb4ec80f25cfbfae8e168360fc00534
Add support for retrieving paths to JSON elements

Add support for retrieving the path to a JSON element. This can for
instance be useful to retrieve paths in deeply nested JSON
structures.

* lisp/json.el (json-pre-element-read-function)
(json-post-element-read-function): New variables to hold pre- and post
read callback functions for `json-read-array' and `json-read-object'.
(json--path): New variable used internally by `json-path-to-position'.
(json--record-path, json--check-position): New functions used
internally by `json-path-to-position'.
(json-path-to-position): New function for retrieving the path to a
JSON element at a given position.
(json-read-object, json-read-array): Call
`json-pre-element-read-function' and `json-post-element-read-function'
when set.

* test/automated/json-tests.el (test-json-path-to-position-with-objects)
(test-json-path-to-position-with-arrays)
(test-json-path-to-position-no-match): New tests for
`json-path-to-position'.
lisp/json.el
test/automated/json-tests.el