How to Install and Use fx in Linux for Interactive JSON Viewing and Processing

Working with nested, complex JSON data in the Linux terminal often leads to frustration when piped into basic pagers. Standard command-line tools such as cat or less dump unformatted text, while utilities like jq require memorising specialised query syntax before you can inspect unfamiliar structures. The fx command is an open-source, interactive terminal JSON viewer and processing tool designed to bridge this gap, offering both an interactive terminal user interface (TUI) for collapsible tree navigation and a full-fledged JavaScript execution engine for streaming data manipulation.

What Is the fx Command in Linux?

Written in Go (with embedded JavaScript runtime capabilities), fx transforms terminal data inspection by rendering JSON into a colourful, expandable hierarchy. You can collapse objects, expand arrays, search keys, copy paths, and execute ad-hoc JavaScript expressions against incoming data streams directly within your terminal window.

Unlike traditional stream processors that require upfront knowledge of the JSON schema, fx allows administrators and developers to inspect payloads visually first, experiment with data extraction interactively, and then automate repetitive queries across shell scripts.

How to Install fx on Linux

Depending on your distribution and package manager preferences, fx can be installed via precompiled binaries, Homebrew, or package managers.

Method 1: Installing via Precompiled Binary (Recommended)

To install the standalone binary directly into your system path without installing external runtimes:

curl -fsSL https://github.com/antonmedv/fx/releases/latest/download/fx_linux_amd64 -o fx
chmod +x fx
sudo mv fx /usr/local/bin/

Method 2: Installing via Snap

If your system supports Snap packages, install fx with a single command:

sudo snap install fx

Method 3: Installing via Homebrew on Linux

For systems using Homebrew on Linux:

brew install fx

Verify that the installation was successful by checking the version:

fx --version

Interactive Navigation with fx

Launching fx in interactive mode is as simple as piping JSON output from another tool or passing a JSON file path as an argument:

curl -s https://api.github.com/repos/antonmedv/fx | fx

Or open a local file directly:

fx server-config.json

When the interactive viewer loads, navigate through the data hierarchy using standard intuitive keyboard shortcuts:

  • Arrow Keys (Up / Down) or j / k: Move the selection cursor vertically across keys and array items.
  • Enter or Space: Expand or collapse the currently selected JSON object or array.
  • e: Expand all child nodes recursively under the active cursor.
  • c: Collapse all child nodes recursively.
  • /: Enter search mode to highlight matching keys, string values, or numbers. Press n for the next match and N for the previous match.
  • p: Copy the JSON path of the selected key directly to your system clipboard (for instance, .data.users[0].email).
  • y: Copy the raw value of the selected element to the clipboard.
  • q or Esc: Exit the interactive viewer and return to your shell prompt.

Non-Interactive JSON Processing and Filtering

Beyond visual inspection, fx functions as a powerful command-line transformer by letting you write native JavaScript functions directly in your pipeline.

Extracting Specific Fields

To pluck a single property from a JSON stream without opening the interactive interface, append JavaScript expressions as arguments:

curl -s https://api.github.com/repos/antonmedv/fx | fx .name .stargazers_count

The dot prefix acts as standard JavaScript property access. You can chain properties together to traverse deeply nested payloads:

fx config.json .database.connections.primary.host

Filtering and Transforming Arrays

Because fx evaluates standard JavaScript methods, you can invoke array primitives such as .map(), .filter(), and .reduce() natively:

cat telemetry.json | fx 'x => x.servers.filter(s => s.status === "active").map(s => s.ip)'

In this syntax, x represents the incoming root JSON object. You receive clean, structured JSON output formatted automatically, ready to pipe to further CLI tools such as awk or curl.

Modifying Data Structures on the Fly

You can reshape data structures inline to generate customised reports or stripped-down configuration payloads:

curl -s https://api.github.com/users/octocat/repos | fx 'x => x.map(r => ({ title: r.name, stars: r.stargazers_count }))'

Managing Custom Helper Functions in fx

If you regularly perform common transformations—such as converting timestamps, decoding Base64 strings, or formatting currencies—you can define reusable JavaScript helper functions inside an fx configuration file.

Create or edit the configuration file at ~/.config/fx/config.js:

mkdir -p ~/.config/fx
nano ~/.config/fx/config.js

Add custom helper functions to the global environment:

global.toDate = (epoch) => new Date(epoch * 1000).toISOString();
global.activeOnly = (items) => items.filter(item => item.enabled);

Save the file. You can now use these custom functions seamlessly across all command-line invocations:

fx logs.json .events 'global.activeOnly'

Frequently Asked Questions

How does fx differ from jq?

While jq is an industry standard designed for fast, stream-oriented data extraction using a custom domain-specific language, fx prioritises exploratory interaction through its collapsible terminal interface and uses standard JavaScript syntax for transformations, eliminating the need to learn specialized DSL operators.

Can fx format and prettify unformatted JSON files?

Yes. Passing a compacted JSON file to fx in non-interactive mode automatically beautifies and colour-codes the output with consistent two-space indentation.

Does fx work with NDJSON (Newline Delimited JSON)?

Yes, fx can stream and parse newline-delimited JSON records sequentially, making it suitable for modern cloud and container log streams.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.