Skip to content

Commit 8cadd2e

Browse files
committed
feat: counsel-jq works equally for JSON and YAML
1 parent f9468f0 commit 8cadd2e

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

README.org

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
* counsel-jq
22

3+
** Live queries against JSON and YAML data
4+
35
[[https://melpa.org/#/counsel-jq][file:https://melpa.org/packages/counsel-jq-badge.svg]]
46

5-
TL;DR: If you're a fan of [[https://stedolan.github.io/jq/][jq]] and you're using Emacs
7+
TL;DR: If you're a fan of [[https://stedolan.github.io/jq/][jq]] or [[https://github.com/mikefarah/yq][yq]] and you're using Emacs
68
[[https://github.com/abo-abo/swiper][Ivy/Swiper/Counsel]], then this package is for you.
79

8-
Longer version: If you are working with complex nested JSON
9-
structures, you are probably familiar with [[https://stedolan.github.io/jq/][jq]] which is like sed for
10-
JSON data and great at what it does. However, being a command-line
11-
tool like sed, the feedback for writing queries and seeing their
12-
results is a discrete process and not live.
10+
Longer version: If you are working with complex nested JSON (or YAML)
11+
structures, you are probably familiar with [[https://stedolan.github.io/jq/][jq]] (or [[https://github.com/mikefarah/yq][yq]]) which is like
12+
sed for JSON data and great at what it does. However, being a
13+
command-line tool like sed, the feedback for writing queries and
14+
seeing their results is a discrete process and not live.
1315

1416
#+begin_quote
1517
Cool. That might even be a feature that would draw in new Emacs users!
@@ -22,20 +24,27 @@ modern completion frameworks like [[https://github.com/abo-abo/swiper][Ivy]], th
2224
inputs, as well.
2325

2426
counsel-jq is a package with which you can quickly test queries and
25-
traverse a complex JSON structure whilst having live feedback. Just
26-
call =M-x counsel-jq= in a buffer containing JSON, then start writing
27-
your =jq= query string and see the output appear live in the message
28-
area. Whenever you're happy, hit =RET= and the results will be
29-
displayed to you in the buffer =*jq-json*=.
27+
traverse a complex JSON and YAML structure whilst having live
28+
feedback. Just call =M-x counsel-jq= in a buffer containing JSON or
29+
YAML, then start writing your =jq= or =yq= query string and see the
30+
output appear live in the message area. Whenever you're happy, hit
31+
=RET= and the results will be displayed to you in the buffer
32+
=*jq-json*=.
3033

3134
Demo:
3235

3336
[[file:images/demo-counsel-jq.gif][./images/demo-counsel-jq.gif]]
3437

3538
** Configuration
3639

37-
By default, the resulting =*jq-json*= buffer will have the major mode
38-
=js-mode=, but that can be customized with the
40+
To define whether you want to use =yq= over =jq= as processing tool,
41+
call =M-x customize= and set =counsel-jq-command= to =yq=.
42+
43+
In the same manner you can define the name of the results buffer by
44+
customizing the =counsel-jq-buffer= variable.
45+
46+
Lastly, by default, the results buffer =*jq-json*= buffer will have
47+
the major mode =js-mode=, but that can be customized with the
3948
=counsel-jq-json-buffer-mode= variable if you prefer =json-mode=,
4049
=rsjx-mode= or any other mode.
4150

counsel-jq.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
;;; counsel-jq.el --- Live preview of "jq" queries using counsel -*- lexical-binding: t -*-
2-
;;; Version: 1.0.1
2+
;;; Version: 1.1.0
33
;;; Author: Alain M. Lafon <[email protected])
44
;;; Package-Requires: ((swiper "0.12.0") (ivy "0.12.0") (emacs "24.1"))
55
;;; Keywords: convenience, data, matching
@@ -16,10 +16,10 @@
1616
:require 'counsel-jq
1717
:group 'counsel-jq)
1818

19-
(defvar counsel-jq-command "jq"
19+
(defcustom counsel-jq-command "jq"
2020
"Command for `counsel-jq'.")
2121

22-
(defvar counsel-jq-buffer "*jq-json*"
22+
(defcustom counsel-jq-buffer "*jq-json*"
2323
"Buffer for the `counsel-jq' query results.")
2424

2525
(defun counsel-jq-json (&optional query)

0 commit comments

Comments
 (0)