https://github.com/sile/jlu
Command-line utilities for on-the-fly investigation of JSON Lines
https://github.com/sile/jlu
command-line-tool json rust
Last synced: about 1 year ago
JSON representation
Command-line utilities for on-the-fly investigation of JSON Lines
- Host: GitHub
- URL: https://github.com/sile/jlu
- Owner: sile
- License: mit
- Created: 2024-07-02T23:57:38.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-04T10:25:40.000Z (almost 2 years ago)
- Last Synced: 2025-03-25T07:12:46.516Z (over 1 year ago)
- Topics: command-line-tool, json, rust
- Language: Rust
- Homepage:
- Size: 37.1 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
jlu
===
[](https://crates.io/crates/jlu)
[](https://github.com/sile/jlu/actions)

```console
$ jlu
Command-line utilities for on-the-fly investigation of JSON Lines
Usage: jlu
Commands:
count Read JSON objects from stdin and count the occurrences of the values associated with the specified top-level member names
flatten Read JSON values from stdin and convert each value into a flattened JSON object
names Read JSON objects from stdin and output the unique member names for all top-level objects
rename Read JSON objects from stdin and rename top-level member names that match a regular expression with a replacement string
table Read JSON objects from stdin and create a markdown table
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
```
Installation
------------
Please execute the following command:
```console
$ cargo install jlu
```
In addition, pre-built binaries for Linux and MacOS are available in [the releases page](https://github.com/sile/jlu/releases).
Command Examples
----------------
### `$ jlu flatten`
```console
$ jlu flatten --help
Read JSON values from stdin and convert each value into a flattened JSON object
Usage: jlu flatten
Options:
-h, --help Print help
$ jq . example0.json
{
"aaa": 1,
"bbb": [
"a",
"b",
"c"
],
"ccc": {
"x": 10,
"y": 20
}
}
$ cat example0.json | jlu flatten | jq .
{
"aaa": 1,
"bbb[0]": "a",
"bbb[1]": "b",
"bbb[2]": "c",
"ccc.x": 10,
"ccc.y": 20
}
```
Note that the following commands assume that the input JSON values are flat JSON objects.
### `$ jlu names`
```console
$ jlu names --help
Read JSON objects from stdin and output the unique member names for all top-level objects
Usage: jlu names
Options:
-h, --help Print help
$ cat example0.json | jlu flatten | jlu names
"aaa"
"bbb[0]"
"bbb[1]"
"bbb[2]"
"ccc.x"
"ccc.y"
```
### `$ jlu rename`
```console
$ jlu rename --help
Read JSON objects from stdin and rename top-level member names that match a regular expression with a replacement string.
For details about regular expressions and replacement strings, please refer to the documentation of the regex crate: https://docs.rs/regex/latest/regex/struct.Regex.html#method.replace_all
Usage: jlu rename
Arguments:
Regular expression to match top-level member names
String to replace the matched segment of the member names
Options:
-h, --help
Print help (see a summary with '-h')
$ cat example0.json | jlu flatten | jlu rename '(.+)\.' '' | jq .
{
"aaa": 1,
"bbb[0]": "a",
"bbb[1]": "b",
"bbb[2]": "c",
"x": 10,
"y": 20
}
```
### `$ jlu count`
```console
$ jlu count --help
Read JSON objects from stdin and count the occurrences of the values associated with the specified top-level member names
Usage: jlu count [NAMES]...
Arguments:
[NAMES]... Names of the top-level members to count
Options:
-h, --help Print help
$ cat example1.json
{"level":"info","msg":"Hello World!"}
{"level":"error","msg":"Hello Rust!"}
{"level":"info","msg":"Hello JSON!"}
$ cat example1.json | jlu count level | jq .
{
"error": 1,
"info": 2
}
$ cat example1.json | jlu count level msg | jq .info
{
"Hello JSON!": 1,
"Hello World!": 1
}
```
### `$ jlu table`
```console
$ jlu table --help
Read JSON objects from stdin and create a markdown table
Usage: jlu table [OPTIONS] [COLUMN_NAMES]...
Arguments:
[COLUMN_NAMES]... Names of object members to be included in the table
Options:
-s, --sort
If specified, the table rows are sorted based on the member value associated with this name
-m, --max-column-chars
Maximum number of characters to display in a column [default: 50]
-h, --help
Print help
$ cat example1.json | jlu table level msg --sort level
| level | msg |
|-------|--------------|
| error | Hello Rust! |
| info | Hello World! |
| info | Hello JSON! |
```