Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ynqa/jnv

Interactive JSON filter using jq
https://github.com/ynqa/jnv

autocomplete cli command-line interactive jq json kubernetes prompt rust

Last synced: 5 days ago
JSON representation

Interactive JSON filter using jq

Awesome Lists containing this project

README

        


Text describing the image

[![ci](https://github.com/ynqa/jnv/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/ynqa/jnv/actions/workflows/ci.yml)

*jnv* is designed for navigating JSON,
offering an interactive JSON viewer and `jq` filter editor.

![jnv.gif](https://github.com/ynqa/ynqa/blob/master/demo/jnv.gif)

Inspired by [jid](https://github.com/simeji/jid)
and [jiq](https://github.com/fiatjaf/jiq).

## Features

- Interactive JSON viewer and `jq` filter editor
- Syntax highlighting for JSON
- Use [jaq](https://github.com/01mf02/jaq) to apply `jq` filter
- This eliminates the need for users to prepare `jq` on their own.

> [!IMPORTANT]
> Starting from v0.3.0, the transition from libjq Rust binding
> [j9](https://github.com/ynqa/j9) to jq clone
> [jaq](https://github.com/01mf02/jaq) was made.
>
> This change eliminated the need to manage C-related dependencies
> that include external tools like autoconf, thus simplifying the build process.
> However, please note that some filters are not yet supported by jaq.
> For more details, refer to GitHub issue
> [#24](https://github.com/ynqa/jnv/issues/24).
>
> Please continue to provide feedback regarding this transition.

- Capable of accommodating various format
- Input: File, Stdin
- Data: A JSON or multiple JSON structures
that can be deserialized with
[StreamDeserializer](https://docs.rs/serde_json/latest/serde_json/struct.StreamDeserializer.html),
such as [JSON Lines](https://jsonlines.org/)
- Auto-completion for the filter
- Only supports:
- [Identity](https://jqlang.github.io/jq/manual/#identity)
- [Object Identifier-Index](https://jqlang.github.io/jq/manual/#object-identifier-index)
- [Array Index](https://jqlang.github.io/jq/manual/#array-index)
- Hint message to evaluate the filter

## Installation

### Homebrew

See [here](https://formulae.brew.sh/formula/jnv) for more info.

```bash
brew install jnv
```

Or install via Homebrew Tap:

```bash
brew install ynqa/tap/jnv
```

### MacPorts

See [here](https://ports.macports.org/port/jnv/) for more info.

```bash
sudo port install jnv
```

### Nix / NixOS

See [package entry on search.nixos.org](https://search.nixos.org/packages?channel=unstable&query=jnv) for more info.

```bash
nix-shell -p jnv
```

### conda-forge

See [here](https://prefix.dev/channels/conda-forge/packages/jnv) for more info.

```bash
pixi global install jnv
# or
cat data.json | pixi exec jnv
# or
conda install jnv
```

### Docker

Build
(In the near future, the image will be available on something of registries)

```bash
docker build -t jnv .
```

And Run
(The following commad is just an example. Please modify the path to the file you want to mount)

```bash
docker run -it --rm -v $(pwd)/debug.json:/jnv/debug.json jnv /jnv/debug.json
```

### Cargo

```bash
cargo install jnv
```

## Examples

```bash
cat data.json | jnv
# or
jnv data.json
```

## Keymap

| Key | Action |
| :- | :- |
| Ctrl + C | Exit |
| Ctrl + Q | Copy jq filter to clipboard |
| Ctrl + O | Copy JSON to clipboard |
| Shift + ↑, Shift + ↓ | Switch to another mode |

### Editor mode (default)

| Key | Action |
| :- | :- |
| Tab | Enter suggestion |
| | Move cursor left |
| | Move cursor right |
| Ctrl + A | Move cursor to line start |
| Ctrl + E | Move cursor to line end |
| Backspace | Delete character before cursor |
| Ctrl + U | Clear entire line |
| Alt + B | Move the cursor to the previous nearest character within set(`.`,`\|`,`(`,`)`,`[`,`]`) |
| Alt + F | Move the cursor to the next nearest character within set(`.`,`\|`,`(`,`)`,`[`,`]`) |
| Ctrl + W | Erase to the previous nearest character within set(`.`,`\|`,`(`,`)`,`[`,`]`) |
| Alt + D | Erase to the next nearest character within set(`.`,`\|`,`(`,`)`,`[`,`]`) |

#### Suggestion in Editor (after Tab)

| Key | Action |
| :- | :- |
| Tab, | Select next suggestion |
| | Select previous suggestion |
| Others | Return to editor |

### JSON viewer mode

| Key | Action |
| :- | :- |
| , Ctrl + K | Move up |
| , Ctrl + J | Move down |
| Ctrl + H | Move to last entry |
| Ctrl + L | Move to first entry |
| Enter | Toggle fold |
| Ctrl + P | Expand all |
| Ctrl + N | Collapse all |

## Usage

```bash
SON navigator and interactive filter leveraging jq

Usage: jnv [OPTIONS] [INPUT]

Examples:
- Read from a file:
jnv data.json

- Read from standard input:
cat data.json | jnv

Arguments:
[INPUT] Optional path to a JSON file. If not provided or if "-" is specified, reads from standard input

Options:
-e, --edit-mode Edit mode for the interface ('insert' or 'overwrite'). [default: insert]
-i, --indent Number of spaces used for indentation in the visualized data. [default: 2]
-n, --no-hint Disables the display of hints.
--max-streams Maximum number of JSON streams to display
--suggestions Number of autocomplete suggestions to show [default: 3]
-h, --help Print help (see more with '--help')
-V, --version Print version
```

## Stargazers over time
[![Stargazers over time](https://starchart.cc/ynqa/jnv.svg?variant=adaptive)](https://starchart.cc/ynqa/jnv)