# Traverse complex JSON structures with live feedback Zen Monk Alain M. Lafon [[!template id=vid src="https://mirror.csclub.uwaterloo.ca/emacsconf/2020/emacsconf-2020--25-traverse-complex-json-structures-with-live-feedback-counsel-jq--zen-monk-alain-m-lafon.webm"]] [Download compressed .webm video (15.8M)](https://mirror.csclub.uwaterloo.ca/emacsconf/2020/smaller/emacsconf-2020--25-traverse-complex-json-structures-with-live-feedback-counsel-jq--zen-monk-alain-m-lafon--vp9-q56-video-original-audio.webm) If you are working with complex nested JSON structures, you are probably familiar with jq 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. 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 and Counsel, 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 structure whilst having live feedback. Just call `M-x counsel-jq` in a buffer containing JSON, then start writing your `jq` 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*`. In this lightning talk, I'll give a quick overview on how to use counsel-jq and how to build similar completion functionality. ## Resources # Questions ## Q4: Any plans for counsel-yq and/or -xq? ;-) counsel-jq currently just shells out to jq. Adding tools build on top of jq (at least yq is afaik) would be very easy. We could employ a strategy pattern to find the right tool based on the current major-mode with a configurable fallback. Here's the place where the shellout happens: Would you be interested in making a PR for that? (; ## Q3: Why repository_url did not autocomplete in addition to the result (I know that it is ivy thing but possible to configure?) There's no autocompletion for the search query, but that would be a great addition. That would theoretically be possibe by employing jq to look ahead in the current tree and providing options for autocomplete. I'm not certain if Ivy does have autocomplete for search queries, though. If somebody has more knowledge on that and would like to ping me up or provide a (draft) PR, I'd be happy to help out in that endeavour! ## Q2: Is it difficult to provide autocompletion for the JSON query in the minibuffer? Good question. I'd be curious, too. It's the same question as Q2 where I went into a possibe scenario. ## Q1: Is it possible to search in arbitrary deep objects? E.g., an AST represented in JSON. counsel-jq uses jq under the hood, so all queries that are valid queries in jq should be valid in jq. Hence, I'm inclined to say 'yes' (; # Notes - 200ok GmbH (). - Play Emacs like an instrument: . - jq: . - ivy supports dynamic sources. So does helm I guess. - counsel-jq: . - organice: . - Entire presentation inside Emacs, with a count down reminder.