#yaml #gron

app fltn

Flattens a serialized data structure making it greppable

22 releases

Uses new Rust 2024

0.3.0 Dec 21, 2025
0.2.9 Aug 9, 2025
0.2.8 Feb 23, 2025
0.2.6 Sep 1, 2024
0.1.0 Feb 25, 2022

#1521 in Encoding

MIT license

90KB
780 lines

Flatten

Latest Version Downloads License Continuous Integration Status

A command line interface (CLI) used to flatten a serialized data structure (e.g., CSV, JSON, TOML, YAML) making it greppable.

Screenshot of json flattening

Inspired heavily by the amazing gron CLI.

Installation

Pre-compiled Binaries

You can download and run the pre-compiled binaries to get up and running immediately.

Cargo

Alternatively, install using cargo:

cargo install fltn

Usage

fltn [OPTIONS] [FILE]

Arguments:
  [FILE]  The serialized data file to be parsed

Options:
  -p, --path <PATH>      JSONPath expression used for querying data
  -f, --format <FORMAT>  Format of serialized data [possible values: csv, json, toml, yaml]
  -c, --color <WHEN>     When to use colors [default: auto] [possible values: never, auto, always]
  -s, --sort             Sort output
  -h, --help             Print help
  -V, --version          Print version

Basic Example

Flatten a JSON file:

$ fltn data.json

Or pipe data through stdin:

$ echo '{"name": "Alice", "age": 30, "active": true}' | fltn
json = {};
json.name = "Alice";
json.age = 30;
json.active = true;

Nested Structures

Nested objects and arrays are flattened into dot notation and bracket notation:

$ cat data.json
{"users": [{"name": "Alice", "role": "admin"}, {"name": "Bob", "role": "user"}]}

$ fltn data.json
json = {};
json.users = [];
json.users[0] = {};
json.users[0].name = "Alice";
json.users[0].role = "admin";
json.users[1] = {};
json.users[1].name = "Bob";
json.users[1].role = "user";

Grep for Values

The flattened output makes it easy to grep for specific values:

$ fltn data.json | grep admin
json.users[0].role = "admin";

JSONPath Filtering

Use JSONPath expressions to filter the data before flattening:

$ fltn --path '$.users[*].name' data.json
json = [];
json[0] = "Alice";
json[1] = "Bob";

Sorted Output

Sort object keys alphabetically with the --sort flag:

$ echo '{"zebra": 1, "apple": 2, "mango": 3}' | fltn --sort
json = {};
json.apple = 2;
json.mango = 3;
json.zebra = 1;

Multiple Formats

The format is auto-detected from the file extension, or can be specified with --format:

CSV:

$ cat data.csv
name,age,city
Alice,30,NYC
Bob,25,LA

$ fltn data.csv
json = [];
json[0] = {};
json[0].name = "Alice";
json[0].age = "30";
json[0].city = "NYC";
json[1] = {};
json[1].name = "Bob";
json[1].age = "25";
json[1].city = "LA";

YAML:

$ cat config.yaml
name: Alice
settings:
  theme: dark
  notifications: true

$ fltn config.yaml
json = {};
json.name = "Alice";
json.settings = {};
json.settings.theme = "dark";
json.settings.notifications = true;

TOML:

$ cat config.toml
[server]
host = "localhost"
port = 8080

$ fltn config.toml
json = {};
json.server = {};
json.server.host = "localhost";
json.server.port = 8080;

Dependencies

~9–14MB
~247K SLoC