Use fx to Inspect JSON: What It Changes and When Plain Output Is Better
A practical review of fx for inspecting JSON in the terminal: what the viewer changes, what it leaves alone, and when raw or plain-text output is the safer choice.
fx is a command-line tool for viewing and exploring JSON. You give it a file or pipe data into it, and it shows the structure in a readable, navigable form. This review covers what fx changes when it displays JSON, where that helps, and where you should use the raw data or plain formatted text instead. No test results or measurements were supplied for this article, so behavior below is described in general terms. Points that depend on your version or environment are marked as things to check.
Is fx suitable for your use?
fx is a good fit when you need to understand unfamiliar or deeply nested JSON quickly. Examples include API responses, configuration files and log payloads. Its main benefit is that it makes structure visible: you can see nesting, expand and collapse parts of the tree, and narrow down to the field you care about.
The main tradeoff is that fx is built for looking at data, not for producing an exact record of it. What you see in an interactive terminal view is a rendering. It is not the same thing as the bytes in the file. If you need to share data, store it, compare it, or feed it to another program, work from the original JSON. Use fx's plain, non-interactive output only if you have confirmed it keeps what you need.
- Plain or raw output is the better choice when:
- the exact original bytes matter, such as for signatures, checksums or diffs against a committed file
- the data contains very large integers or high-precision numbers, and you have not confirmed how your fx version handles them
- the result is going into a ticket, chat message, document or another tool rather than staying in your terminal
- the reader relies on a screen reader or other assistive technology
- you are scripting, and a full-screen interface would get in the way
What fx actually changes
In this context, 'transformation' means formatting and presentation. fx does not reverse, mirror or substitute characters, and it applies no font styling to the text itself. There are two separate things to keep apart.
The first is visual presentation in the interactive viewer. fx parses the JSON and draws it as a tree. It adds indentation, may add color and may collapse sections. Collapsing hides content on screen but does not delete it from the data. Color in a terminal usually comes from escape sequences sent to the terminal. Those sequences are not part of the JSON values.
The second is printed output. When fx writes formatted JSON to standard output, the whitespace differs from the input. Compact JSON becomes indented, or the reverse. Whitespace between JSON tokens carries no meaning, so this kind of reformatting keeps the data the same. Your input file is not modified unless you explicitly redirect output over it.
Here is a simple illustration. A compact input like this:
{"name":"Ada","tags":["math","engines"],"active":true}
would be shown as an indented structure along these lines. The exact indentation and coloring depend on the version and settings:
{
"name": "Ada",
"tags": [
"math",
"engines"
],
"active": true
}
The keys, values, string contents and order are the same in both forms. Only the whitespace between tokens differs. That is the expected result for a pure formatting step. If the output changed a string, a number or the key order, that would be a real change to the content, not formatting.
Where meaning can drift
Parsing and re-printing JSON is not always a lossless round trip. The cases below depend on implementation, and the supplied material did not confirm how current fx handles them. Treat them as things to test with your own data:
- Large numbers: tools that store JSON numbers as double-precision floats can silently round integers beyond about 2^53, as well as long decimals. Earlier JavaScript-based versions of fx were exposed to this. Check your installed version against a known large value before trusting its output for IDs or financial figures.
- Number formatting: a value written as 1.0 or 1e3 may be printed in a different but equivalent form after re-serialization.
- Duplicate keys: the JSON standard does not define how duplicate keys must be handled. A parser may keep the last one, keep the first one, or reject the input.
- String escapes: escaped Unicode, such as \u00e9, may be printed as the literal character, or the reverse. The value is the same, but the bytes differ.
- Invalid input: if the file is not valid JSON, fx should report an error rather than display it. Confirm this rather than assuming partial input was shown in full.
Basic ways to use it
Common invocation patterns are shown below. Flags and expression syntax have changed across fx releases, so check the help output of the version you install before relying on any specific form.
# Open a file in the interactive viewer
fx data.json
# Pipe JSON from another command
cat data.json | fx
# Print a selected field instead of opening the viewer
fx data.json .users
# Check the options your installed version supports
fx --help
Passing a field expression is useful when you already know what you want. It also gives text output that is easier to copy or pass along than a full-screen view.
Will the result stay usable after copying or sharing?
It depends on what you copy. Selecting text from the interactive viewer copies what the terminal shows. Collapsed sections, truncated lines and on-screen markers may come along or go missing, depending on the terminal. The copied text may not be valid JSON, and it may be incomplete. For anything you plan to share, copy from printed output or from the original file instead.
Color is a second concern. If color escape sequences end up in redirected or piped output, the result can contain stray control characters. Those break JSON parsers and look like garbage in chat tools and documents. Many command-line tools turn color off automatically when output is not a terminal. Confirm that your fx version does the same before you rely on it, for example by redirecting to a file and running that file through a separate JSON validator.
Search and editing are not affected by formatting. Indented JSON is still JSON, and text search finds the same keys and values. One exception is when escape handling differs, as noted above.
Accessibility limits
The supplied material did not document fx's accessibility. As a general rule, full-screen terminal interfaces that redraw the screen, rely on color, and are navigated by cursor movement work less reliably with screen readers than line-by-line text output. fx has not been tested here with any named assistive technology.
For readers who use assistive technology, give them plain indented JSON as text. Do not use screenshots of the viewer or color-only cues. When structure matters, describe the relevant path in words, for example 'users, first item, email'.
Bottom line
fx is well suited to reading and exploring JSON in your own terminal. Its formatting changes presentation and whitespace, not the data, as long as the parse and re-print round trip is faithful. That round trip is the part to verify with large numbers, duplicate keys and escaped characters. For sharing, storage, comparison or accessible reading, use the original file or plain printed output that you have checked.