-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5d13a2
commit bea258a
Showing
3 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#+title: Using Jmespath in Emacs | ||
#+AUTHOR: Shubham Kumar | ||
#+DATE: 2024-02-06 | ||
#+PROPERTY: description: Querying JSON files/data using Jmespath library in Emacs | ||
#+PROPERTY: draft: false | ||
#+PROPERTY: heroImage: /hero-images/default.png | ||
#+PROPERTY: ideaDate: Feb 06, 2024 | ||
|
||
* 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. | ||
#+begin_src bash | ||
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 | ||
#+end_src | ||
|
||
** Mac | ||
On Mac, you can install Jmespath CLI using `brew`. | ||
#+begin_src bash | ||
brew install jmespath/jmespath/jp | ||
#+end_src | ||
|
||
* Adding Jmespath recipe in Emacs | ||
|
||
This is my first recipe that I published on [[https://melpa.org/][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~. | ||
#+begin_src elisp | ||
(package! jmespath) | ||
#+end_src | ||
|
||
2. Also, add the below line in your ~config.el~. | ||
#+begin_src elisp | ||
(use-package jmespath) | ||
#+end_src | ||
|
||
* 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 [[https://jmespath.org/][Jamespath page]]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
title: Using Jmespath in Emacs | ||
AUTHOR: Shubham Kumar | ||
DATE: 2024-02-06 | ||
description: Querying JSON files/data using Jmespath library in Emacs | ||
draft: false | ||
heroImage: /hero-images/default.png | ||
ideaDate: Feb 06, 2024 | ||
--- | ||
|
||
|
||
## 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. | ||
```bash | ||
> 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 | ||
``` | ||
|
||
### Mac | ||
On Mac, you can install Jmespath CLI using `brew`. | ||
```bash | ||
> brew install jmespath/jmespath/jp | ||
``` | ||
|
||
## Adding Jmespath recipe in Emacs | ||
|
||
This is my first recipe that I published on [MELPA](https://melpa.org/).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`. | ||
```elisp | ||
> (package! jmespath) | ||
``` | ||
|
||
2. Also, add the below line in your `config.el`. | ||
```elisp | ||
> (use-package jmespath) | ||
``` | ||
|
||
## 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](https://jmespath.org/). |