Giter VIP home page Giter VIP logo

counsel-jq's Introduction

counsel-jq

Live queries against JSON and YAML data

https://melpa.org/packages/counsel-jq-badge.svg

TL;DR: If you’re a fan of jq or yq and you’re using Emacs Ivy/Swiper/Counsel, then this package is for you.

Longer version: If you are working with complex nested JSON (or YAML) structures, you are probably familiar with jq (or yq) which is like sed for JSON data and great at what it does. However, being a command-line tool like sed, the feedback for writing queries and seeing their results is a discrete process and not live.

Cool. That might even be a feature that would draw in new Emacs users!

(alphapapa during the melpa submission)

When working with Emacs, we are used to good auto-completion and live feedback. Formerly, this was mostly done with static input, but with modern completion frameworks like Ivy, this can be done with dynamic inputs, as well.

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

Demo:

./images/demo-counsel-jq.gif

Configuration

To define whether you want to use yq over jq as processing tool, call M-x customize and set counsel-jq-command to yq.

In the same manner you can define the name of the results buffer by customizing the counsel-jq-buffer variable.

Lastly, by default, the results buffer *jq-json* buffer will have the major mode js-mode, but that can be customized with the counsel-jq-json-buffer-mode variable if you prefer json-mode, rsjx-mode or any other mode.

EmacsConf 2020 talk on counsel-jq

On [2020-11-29 Sun], Zen Monk Alain M. Lafon (@munen) gave a talk at EmacsConf 2020 introducing counsel-jq. There’s a video recording with explanations and demos behind this complementary blog post: https://200ok.ch/posts/2020-11-30_emacsconf_traverse_complex_json_structures_with_live_feedback_with_counseljq.html

counsel-jq's People

Contributors

gilbertw1 avatar gleek avatar mcraveiro avatar munen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

counsel-jq's Issues

Installation from MELPA doesn't work

I tried to install via MELPA. I didn't previously have counsel installed, and it failed to install it. It seems to depend on the ivy package, but on the swiper file which is (presumably) in the swiper package which was not installed automatically.

On the other hand, the swiper package depends on ivy, so it seems that this should depend on swiper instead. And perhaps the counsel package as well (or maybe the name is wrong)?

Compiling file /Users/iandrus/.emacs.d/elpa/counsel-jq-20191202.846/counsel-jq.el at Mon Dec  2 14:09:55 2019
Entering directory ‘/Users/iandrus/.emacs.d/elpa/counsel-jq-20191202.846/’
counsel-jq.el:12:1:Error: Cannot open load file: No such file or directory, swiper

Error when querying for keys

When I use jq over the cli, querying for keys like this works fine:

code-dev/api » jq 'keys' test.json
[
  "has_more",
  "items",
  "quota_max",
  "quota_remaining"
]

When I try to do the same thing with counsel-jq (query for 'keys') on the same file, I get the following error:
jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?)

Environment is doom emacs, anyone encounter the same issue yet?

`counsel-jq` doesn't always use the correct source buffer

Hi,

I've found that counsel-jq when invoked doesn't always use the buffer it was invoked from when evaluating it's queries. I've noticed in a number of cases it instead using a different buffer from the one it was invoked from.

The specific use case that fails for me in doom-emacs is to open a new empty buffer (evil-buffer-new), paste in a json block, then execute counsel-jq. In this scenario counsel-jq will never use the newly created buffer, but instead whichever buffer was selected prior.

I'm not positive, but I believe this is likely the result of using workspace features (such as persp-mode) to curate and separate buffers into specific workspaces. In the case of more transient buffers, it seems that the buffer-list and other-buffer aren't always reliable to always get the last selected buffer.

Gives wrong results with `ivy-occur`

ivy-occur can be used to get the filtered results in a separate buffer.
It is similar to the default action which opens up the result in *jq-json* buffer but instead uses an occur buffer.

This can help in filtering multiple json objects and compare the filtered results without having subsequent runs replace the results of previous ones.

Running ivy-occur (C-c C-o by default I think) opens up the full json object instead of only displaying the filtered results.

I'm unsure of what might be causing this or if this is a bug upstream in ivy.

error when first running counsel-jq

windows 10, emacs 26.3

just installed jq (from chocolatey) and counsel-jq

When in json buffer, M-x counsel-jq, immediately get following:

Error in post-command-hook (icomplete-post-command-hook): (wrong-number-of-arguments (1 . 1) 3)
Quit

Then get prompt for jq query.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.