fx: Interactive and Scriptable JSON Processor
fx opens JSON in an interactive viewer, and when given function arguments it runs them as JavaScript reducers over the data, so the same tool explores and transforms.
fx is a two-in-one: run it with just a file to browse interactively, or pass JavaScript expressions to filter and map in a pipeline. This page focuses on the scriptable mode for CI; the base reference is fx-json-transform.
What it does
In script mode, fx reads JSON on stdin and applies each argument as a function of the current value. A .field shorthand selects a property, and an arrow function like x => x.filter(...) transforms arrays. Arguments chain left to right, each receiving the previous result.
Common usage
echo '{"a":{"b":1}}' | fx .a.b
cat users.json | fx 'x => x.filter(u => u.age > 30)' '.length'
# map to a field, one JSON value per pipe stage
curl -s https://api.example.com/users | fx '.[]' .nameOptions
| Argument form | What it does |
|---|---|
| .path | Select a nested property (dot access) |
| x => ... | Anonymous JS function applied to the current value |
| (chained args) | Each argument transforms the previous result |
| --help | Show usage and version |
In CI
fx is handy when transformation logic is naturally JavaScript (nested map/filter/reduce). Because each argument is real JS, you can compute derived values inline. For simple extraction jq is more portable, but fx wins when the reshape is awkward to express as a jq filter and your image already has fx.
Common errors in CI
A bad function argument throws the underlying JS error, e.g. "TypeError: Cannot read properties of undefined (reading 'name')" when a field is missing; guard with optional chaining u?.name. "SyntaxError: Unexpected token" means a malformed arrow function, often unbalanced quotes from the shell. Non-JSON on stdin produces a parse error before any function runs.