Getting Started
Fx is a CLI for JSON: it shows JSON interactively in your terminal, and lets you transform JSON with JavaScript. Fx is written in Go and uses goja as its embedded JavaScript engine.
Run this command to start fx in interactive mode:
fx data.json
JSON Processing
In fx, arguments are treated as JavaScript functions. Input data is passed sequentially through each provided function:
echo '{"name": "world"}' | fx 'x => x.name' 'x => `Hello, ${x}!`'
You can also utilize standard JavaScript functions:
echo '{"name": "world"}' | fx 'Object.keys'
Fx also introduces syntactical sugar to enhance simplicity:
- Reference input data using
x
orthis
. - Start expressions with
.
to avoid repeating thex => x
.
echo '{"name": "world"}' | fx .name '`Hello, ${x}!`'
That's it. So simple!
INFO
Fx is short for f(x)
, capturing the essence of applying a function to input data.
Streaming Mode
Fx is designed to handle both line-delimited JSON and concatenated JSON streaming:
echo '{"text": "Hello"}{"text": "World!"}' | fx .text
Output:
Hello
World!
For collective processing of a JSON stream as a single array, use the --slurp
or -s
flag:
echo '{"text": "Hello"}{"text": "World!"}' | fx --slurp '.map(x => x.text)' '.join(", ")'
Output:
Hello, World!
Interactive Mode
Fx provides an interactive mode that allows you to explore JSON interactively. To initiate the interactive mode, pipe a JSON into fx:
curl -i https://fx.wtf/example.json | fx
TIP
Yes, fx can show curl headers (with the -i
flag) in the interactive mode.
Or:
fx example.json
TIP
If you forget the available commands, press ? to display the key bindings.
Navigating
Easily navigate through your JSON using arrows keys or vim keys.
Press . to adjust the current path. Press tab or . to opt for the current suggestion.
Press @ to start a fuzzy search of JSON paths and jump to the first match.
Press [ or ] to jump to the previous location or to the next location in history.
Searching
Press /, enter a regex pattern, press enter. Navigate to the next search result with n and to the previous search result with N.
By default, the search is case-insensitive. However, you can modify search sensitivity:
Case-Sensitive: Add /
at the pattern's end.
/[a-z]/
Case-Insensitive: Append /i
flag.
/[a-z]/i
Printing
Fx uses stderr for rendering, allowing you to print values to stdout.

Press p to preview the current value. Press P to print the value to stdout.
You can use fx to select only specific part of the JSON and save it to a file:
curl ... | fx > output.json
Text Selection
Text selection in fx differs due to mouse event redirection to stdin. Depending on your terminal, use specific key combinations to select text:
Key | Terminal |
---|---|
fn | Terminal.app |
option | iTerm2, Hyper |
shift | Linux |
TIP
To disable mouse event redirection, specify the FX_NO_MOUSE
environment variable.