/jjumper

Emacs function to quickly jump to a nested json key

Primary LanguageEmacs Lisp

jjumper.el

Quickly jump to a nested key in a json buffer

Overview

https://github.com/flocks/jjumper/raw/main/jjumper.gif

Installation

You can just put `jjumper.el` somewhere in your load-path and eval the file. You can also use use-package with straight:

 (use-package jjumper
	:straight (jjumper :type git :host github :repo "flocks/jjumper")
	:config
	(define-key json-mode-map (kbd "C-c C-j") 'jjumper-jump-key))

Usage

The most common usecase, is to bind jjumper-jump-key to some convenience keychord in json-mode-map

(define-key json-mode-map (kbd "C-c C-j") 'jjumper-jump-key)

Other usecases

Since it’s using native completion system (completing-read), you can leverage embark for copying the path, or inserting somewhere.

I personnaly use it in a frontend application, where all translations keys are stored in a single json file. I can quickly search and insert a path in my code with the following snippet:

 (defun ft-insert-translation-key ()
	"Insert a translation key"
	(interactive)
	(let ((key (with-current-buffer
				   (find-file-noselect "~/project/path/to/translation.json")
				 (jjumper--prompt (jjumper--get-json-in-buffer)))))
	  (insert key)))

Todo

  • Potentially handle different configuration format like YAML