fx: View and Transform JSON, Non-Interactively
fx is an interactive JSON viewer that also runs non-interactively: pass it field accessors or anonymous functions and it streams the transformed JSON.
Locally fx opens a TUI to explore JSON. In CI you use it as a processor: it takes JavaScript-style accessors and functions, a friendlier syntax than jq for some transforms.
What it does
Given JSON on stdin and one or more arguments, fx applies each in turn. An argument starting with . is a field path; an argument like x => x.length is an anonymous function. With no arguments and a TTY it opens the interactive viewer instead.
Common usage
# access a nested field
echo '{"user":{"name":"ada"}}' | fx .user.name
# map over an array with a function
curl -s https://api.example.com/users | fx '.items' 'x => x.map(u => u.id)'
# chain accessors
cat data.json | fx .results[0].statusOptions
| Form | What it does |
|---|---|
| .field.path | Access a nested field |
| .array[0] | Index into an array |
| 'x => ...' | Anonymous function applied to the input |
| multiple args | Each argument is applied in sequence |
| this | Refers to the current value inside a function |
| -r, --raw | Treat input as raw strings (NDJSON-friendly) |
In CI
Use fx to reshape an API response with familiar JavaScript: curl -s "$API" | fx ".data" "d => d.filter(x => x.active).length" returns a count you can branch on. Because the function syntax is JS, complex maps/filters can read more clearly than the equivalent jq.
Common errors in CI
fx: command not found: install with npm i -g fx (Node) or a standalone binary. The biggest CI gotcha is that with no processing arguments fx tries to open the interactive viewer and fails or hangs with no TTY (the input device is not a TTY); always pass at least one accessor/function in scripts. A SyntaxError means the JS function argument is malformed (often unbalanced quotes from the shell).