DEV Community

Shubham Kumar
Shubham Kumar

Posted on • Originally published at shubham.codes on

Using Jmespath in Emacs

Introduction

When you have a small JSON file, it is quite easy to look for what you want. But querying a large JSON data is very troublesome.

This is where people use tools like Jmespath to filter and transform data into their liking. This post is about a small wrapper over jp CLI utility that you can use while working on JSON files in Emacs.

Installing JP

Linux

On Linux, you can install the utility by first downloding the binary and then installing it.

> sudo wget https://github.com/jmespath/jp/releases/latest/download/jp-linux-amd64 \
> -O /usr/local/bin/jp && sudo chmod +x /usr/local/bin/jp

Enter fullscreen mode Exit fullscreen mode

Mac

On Mac, you can install Jmespath CLI using brew.

> brew install jmespath/jmespath/jp

Enter fullscreen mode Exit fullscreen mode

Adding Jmespath recipe in Emacs

This is my first recipe that I published on MELPA.Here are the steps to install it in Doom using straight. You can use any package manager to install it using MELPA repository.

Doom Emacs

  1. On Doom, you can just mention the below recipe in your package.el.
> (package! jmespath)

Enter fullscreen mode Exit fullscreen mode
  1. Also, add the below line in your config.el.
> (use-package jmespath)

Enter fullscreen mode Exit fullscreen mode

Using Jmespath

There is an interactive function, jmespath-query-and-show that you can use to query the currently opened buffer or a file. To use it with current buffer, you can simply call this function and enter your query. The output will be shown on a new buffer with name JMESPath Result.

To use this with a different file, you can set the Universal Argument using C-u or SPC-u (using evil). Then you can enter the file to execute the query on.

Read more

To learn more about JMESPath, visit Jamespath page.

Image of Quadratic

Python + AI + Spreadsheet

Chat with your data and get insights in seconds with the all-in-one spreadsheet that connects to your data, supports code natively, and has built-in AI.

Try Quadratic free

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️