Terminal JSON viewer

fx preview

* Function eXecution

Features

  • Mouse support
  • Streaming support
  • Preserves key order
  • Preserves big numbers

Install

brew install fx
snap install fx
scoop install fx
pacman -S fx
pkg install fx
go install github.com/antonmedv/fx@latest

Or download pre-built binary.

Usage

Start the interactive viewer via:

fx data.json

Or

curl ... | fx

Type ? to see full list of key shortcuts.

Pretty print:

curl ... | fx .

Reducers

Write reducers in your favorite language: JavaScript (default), Python, or Ruby.

fx data.json '.filter(x => x.startsWith("a"))'
fx data.json '[x["age"] + i for i in range(10)]'
fx data.json 'x.to_a.map {|x| x[1]}'

Documentation

See full documentation.

Themes

Theme can be configured by setting environment variable FX_THEME from 1 to 9:

export FX_THEME=9

themes

Add your own themes in theme.go file.

License

MIT

Owner
Anton Medvedev
SRE at Google
Anton Medvedev
Comments
  • MINGW64/Cmder issue on Windows?

    MINGW64/Cmder issue on Windows?

    I have just installed FX on Windows, on Cmder, using NPM. But there is some issue (an assertion failure in some C++ code?)

    fgeorges@xxx /c/home/xxx
    λ npm i fx -g
    C:\Users\fgeorges\AppData\Roaming\npm\fx -> C:\Users\fgeorges\AppData\Roaming\npm\node_modules\fx\index.js
    + [email protected]
    added 15 packages from 7 contributors in 3.567s
    
    fgeorges@xxx /c/home/xxx
    λ fx xxx.json
    MINGW64:/c/home/xxx[10072]: src\node_file.cc:1523: Assertion `(argc) == (5)' failed.
     1: 00007FF7E010ABAA v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4810
     2: 00007FF7E00B0C96 uv_loop_fork+80486
     3: 00007FF7E00B0D4F uv_loop_fork+80671
     4: 00007FF7E00A5E7D uv_loop_fork+35917
     5: 00007FF7E051367E v8::internal::interpreter::HandlerTableBuilder::HandlerTableBuilder+59870
     6: 00007FF7E0514BE0 v8::internal::interpreter::HandlerTableBuilder::HandlerTableBuilder+65344
     7: 00007FF7E0513B79 v8::internal::interpreter::HandlerTableBuilder::HandlerTableBuilder+61145
     8: 00007FF7E0513A5B v8::internal::interpreter::HandlerTableBuilder::HandlerTableBuilder+60859
     9: 000002C1D1850361
    
    fgeorges@xxx /c/home/xxx
    λ
    
  • Feature request: Copy result to clipboard.

    Feature request: Copy result to clipboard.

    Maybe that feature exists but It would be great if users could copy their search results or some fields to clipboard. I know about the ability to select but it now what I want

  • Extract sub-object in interactive mode

    Extract sub-object in interactive mode

    When sub-object is selected in interactive mode, by pressing x or Ctrl-e sub-object is printed to stdout in this form:

    $ <t2.json fx
    {
      "a": 11,
      "b": {
        "c": 33
      }
    }
    
    $ <t2.json fx # .b is interactively selected, key `x` is pressed
    {
      "path": ".b",
      "value": {
        "c": 33
      }
    }
    

    I had to do some changes around handling piped/TTY input and output and command line arguments. It should support all existing modes of use.

    This should also close #132

    Best regards!

    UPDATE: I removed anything about completely unneeded interactive mode forcing flags. PR is now only about interactive mode action for extraction of sub-object to support semi-interactive workflows discussed in the PR.

  • EACCES: permission denied, on Ubuntu 18.04

    EACCES: permission denied, on Ubuntu 18.04

    Not working after installing with Snap on Ubuntu 18.04.

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID:	Ubuntu
    Description:	Ubuntu 18.04.1 LTS
    Release:	18.04
    Codename:	bionic
    
    $ ls -lah composer.json 
    -rwxrwxrwx 1 devrck devrck 4.0K Oct  8 16:12 composer.json
    
    $ fx composer.json 
    fs.js:642
      return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                     ^
    
    Error: EACCES: permission denied, open 'composer.json'
        at Error (native)
        at Object.fs.openSync (fs.js:642:18)
        at Object.fs.readFileSync (fs.js:510:33)
        at main (/snap/fx/24/lib/node_modules/fx/index.js:52:16)
        at run (/snap/fx/24/lib/node_modules/fx/index.js:80:5)
        at Object.<anonymous> (/snap/fx/24/lib/node_modules/fx/index.js:98:1)
        at Module._compile (module.js:577:32)
        at Object.Module._extensions..js (module.js:586:10)
        at Module.load (module.js:494:32)
        at tryModuleLoad (module.js:453:12)
    
  • Add snapcraft support for building snaps

    Add snapcraft support for building snaps

    I’ve been using fx for a while to make consumption of various APIs more palatable on the command line. I wish I’d know about it earlier, as it’s far superior to jq! :)

    This pull request enables creation of a snap package of fx. The single snap (built for many architectures) in the Snap Store will be installable on numerous popular Linux distributions with no changes. It’ll also be discoverable via the Snap Store, where releases are under your control.

    If you're willing to publish this under the fx project name, you just need to create an account and then register the fx name.

    A snap file created by snapcraft (our free software tool for building snaps) can then be released in the Snap Store with snap push --release stable *.snap. You'll want to install snapcraft (brew install snapcraft, snap install snapcraft, or apt install snapcraft) and login (snapcraft login) first, though.

    You may also want to consider using https://build.snapcraft.io/ which is a free build service, that can create armhf, amd64, i386, arm64 and other builds of fx, and push them to the store automatically. Alternatively it’s possible to integrate publishing the snap via a third party CI system such as travis or circle-ci.

    I appreciate snaps and snapcraft may be a new thing to you, so I’d be happy to answer any questions you may have.

  • Display current path

    Display current path

    Hi,

    I use fx a lot to explore big json files and do some searches onto it. But I'd like to know "where I am" in file when on a result.

    Current path could be added at the bottom of screen.

    What do you think of that ?

  • Searching

    Searching

    This is modeled after vim's search behavior. Using this as an example:

    $ fx <(curl -s https://next.json-generator.com/api/json/get/VkCpIMn1U)
    
    1. Hit / to start/resume searching
    2. Enter strawberry as a plaintext search, and then hit <enter>
    3. You'll see 1 of 4 found: [0].favoriteFruit, and the JSON will expand to that path and put the cursor on the proper line: at that point, you can move around as normal, with the addition of n to go to the next search hit, and p to go back to the previous one.
    4. You can also use a regex: hit /, and the C-u to erase the previous search and enter /t(ue|hur)sday/i (note the regex syntax), and you'll see two hits
    5. Searching also includes the keys, ie eyeColor will find the 9 "eyeColor" keys in the example JSON

    The majority of this search functionality is in its own search module, the only changes to fx.js are:

    1. Adding an event listener box.on('focus', ...) which is how the search module tells the main screen to update

    2. Modifying the render method to optionally take a path argument, which the focus handler uses to tell render() which line to put the cursor on

    I also grouped some of the smaller functions lying around into helpers.js: walk (which I added a few optional arguments to), reduce, and the new log function are all in there. This was mostly because I needed walk in search.js. Also, that log() function doesn't do anything unless you define a log: "/tmp/some-file-name.log" entry in config.js.

  • [New] add `--indent` CLI arg; add tabs support

    [New] add `--indent` CLI arg; add tabs support

    Fixes #121

    Happy to add tests and usage examples if this is the right direction to be going.

    (Separately, i think thinks would be a lot cleaner if you used something like yargs as an arg parser, but that's out of scope for this PR)

  • "{,x}" causes fx to crash

    Thanks for this really cool tool!

    $ echo '"{,x}"' | fx
    TypeError: Cannot read property 'slice' of null
        at /home/lydell/.npm-global/lib/node_modules/fx/node_modules/neo-blessed/lib/program.js:2543:35
        at Array.forEach (<anonymous>)
        at Program._attr (/home/lydell/.npm-global/lib/node_modules/fx/node_modules/neo-blessed/lib/program.js:2542:11)
        at Box.Element._parseTags (/home/lydell/.npm-global/lib/node_modules/fx/node_modules/neo-blessed/lib/widgets/element.js:498:26)
        at Box.Element.parseContent (/home/lydell/.npm-global/lib/node_modules/fx/node_modules/neo-blessed/lib/widgets/element.js:393:22)
        at Box.Element.setContent (/home/lydell/.npm-global/lib/node_modules/fx/node_modules/neo-blessed/lib/widgets/element.js:335:8)
        at render (/home/lydell/.npm-global/lib/node_modules/fx/fx.js:248:9)
        at start (/home/lydell/.npm-global/lib/node_modules/fx/fx.js:253:3)
        at main (/home/lydell/.npm-global/lib/node_modules/fx/index.js:42:20)
        at Socket.stdin.on (/home/lydell/.npm-global/lib/node_modules/fx/index.js:109:5)
    

    I'm using 3.0.2.

  • Doesn't work on windows

    Doesn't work on windows

    On windows (Windows 10/64 Bit) it fails with the error:

    fs.js:119
        throw err;
        ^
    
    Error: ENOENT: no such file or directory, open '/dev/tty'
        at Object.openSync (fs.js:443:3)
        at start (C:\Users\sbiedermann\.npm-global\node_modules\fx\fx.js:9:20)
        at main (C:\Users\sbiedermann\.npm-global\node_modules\fx\index.js:42:20)
        at Socket.stdin.on (C:\Users\sbiedermann\.npm-global\node_modules\fx\index.js:109:5)
        at Socket.emit (events.js:187:15)
        at endReadableNT (_stream_readable.js:1081:12)
        at process._tickCallback (internal/process/next_tick.js:63:19)
    
  • [feature request] support line-delimited JSON format

    [feature request] support line-delimited JSON format

    Streams of records are often produce as separated lines instead of an array object with opening bracket, commas and closing bracket.

    This format is Line-delimited JSON (jsonl)

    Instead of

    [
    {"record":"a"},
    {"record":"b"},
    {"record":"c"}
    ]
    

    we have

    {"record":"a"}
    {"record":"b"}
    {"record":"c"}
    

    Currently fx returns SyntaxError: Value expected (char 0).

    jq supports it.

  • [feature] Support VS Code settings.json and launch.json style config files

    [feature] Support VS Code settings.json and launch.json style config files

    VS Code uses .json files in its ~/.vscode directory, but they are unable to be loaded.

    OS: Lubuntu 21.10

    Errors:

    JSON Parse Error: invalid character '}' looking for beginning of object key string
    
    JSON Parse Error: invalid character '/'
    
  • fix(sec): upgrade gopkg.in/yaml.v3 to 3.0.0

    fix(sec): upgrade gopkg.in/yaml.v3 to 3.0.0

    What happened?

    There are 1 security vulnerabilities found in gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c

    What did I do?

    Upgrade gopkg.in/yaml.v3 from v3.0.0-20200313102051-9f266ea9e77c to 3.0.0 for vulnerability fix

    What did you expect to happen?

    Ideally, no insecure libs should be used.

    The specification of the pull request

    PR Specification from OSCS

  • Support different styles (including ascii) for size display in preview

    Support different styles (including ascii) for size display in preview

    Environment var FX_SHOW_SIZE can contain different styles of unicode ranges beside "subscript"

    "subscript": What you would get with "true" up until this. \u2080 forward "mono": Unicode monospace digits. \U0001D7F6 forward "bold": Unicode math bold digits. \U0001D7CE forward "sans": Unicode math sans bold digits.
    "doublestruck": Unicode math doublestruck digits. \U0001D7D8 forward "true" or any other string: Plain ascii

    New comments too with preview:

    • // Subscript ₀₁₂₃₄₅₆₇₈₉
    • // Math Monospace 𝟶𝟷𝟸𝟹𝟺𝟻𝟼𝟽𝟾𝟿
    • // Math bold digit 𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗
    • // Math bold sans serif 𝟬𝟭𝟮𝟯𝟰𝟱𝟲𝟳𝟴𝟵
    • // Math double struck 𝟘𝟙𝟚𝟛𝟜𝟝𝟞𝟠𝟡
    • // Ascii 0123456789
  • fix: stdout and stderr behavior

    fix: stdout and stderr behavior

    I had a problem with piping fx to xargs, specifically things like this weren't working properly:

    global.list = json => (json.forEach(x => console.log(x)), undefined)
    

    Whenever I tried to use console.log reducers were acting weirdly, for example: image

    After some investigation I've realized that stderr from reducer processes was being mixed with stdout (which was the main issue) and also that pretty printing was misbehaving when stdout contained anything other than the reduced object.

    So, I've cleaned up the code a little and now it works like this: image

    Also, reducers now can return an object regardless of whether console.log was used or not. It looks like this: image

  • Question: how to enable interactive mode?

    Question: how to enable interactive mode?

    I just installed fx on a Mac (using brew install fx, which installed version 24.0) in combination with zsh. For some reason, commands like fx data.json just spits out the highlighted JSON to stdout, but not much else (very similar to what jq data.json does). How do I enter interactive mode?

Json-match - Command line util for matching values in a JSON input

json-match Match JSON input by specifying key and value > json-match -json '{\"p

Jan 12, 2022
Terminal client for SimpleNote

GoNote - Terminal client for SimpleNote GoNote is a simple utility for managing notes in your SimpleNote account. It allows basic operations like crea

Nov 22, 2022
gomerge is a tool to quickly bulk merge several pull requests from your terminal.
gomerge is a tool to quickly bulk merge several pull requests from your terminal.

Gomerge is a tool to quickly enable you to bulk merge Github pull requests from your terminal. The intention of this tool is to simplfy, and eventually automate the merging of github pull requests. This tool should be able to run on most systems.

Dec 28, 2022
`tmax` is a powerful tool to help you get terminal cmd directly.
`tmax`  is a powerful tool to help you get terminal cmd directly.

The positioning of tmax is a command line tool with a little artificial intelligence. If you frequently deal with the terminal daily, tmax will greatly improve your work efficiency.

Oct 15, 2022
YouTube client on your terminal

MeowTube YouTube client on your terminal Table of Contents About Getting Started Usage Contributing About MeowTube is a CLI (Command Line Interface) t

Jul 29, 2022
🎄 A Christmas tree right from your terminal!
🎄 A Christmas tree right from your terminal!

ctree ?? A Christmas tree right from your terminal! ?? Demo ⌛ No Refresh Don't want the tree to refresh every 2 seconds? Easy! Just add the --no-refre

Dec 20, 2022
progress_bar creates a single customizable progress bar for Linux terminal.
progress_bar creates a single customizable progress bar for Linux terminal.

progress_bar Go Progress Bar Features progress_bar creates a single customizable progress bar for Linux terminal. Installation go get -u github.com/er

Aug 12, 2022
A terminal based typing test.
A terminal based typing test.

What A terminal based typing test. Installation Linux sudo curl -L https://github.com/lemnos/tt/releases/download/v0.4.0/tt-linux -o /usr/local/bin/tt

Dec 28, 2022
Raspberry Pi terminal based activity monitor
Raspberry Pi terminal based activity monitor

pitop Raspberry Pi terminal based activity monitor Yes I know there are plenty of solutions already available, but I wanted to build my own terminal b

Dec 11, 2022
❓🖼 Find the anime scene by image using your terminal
❓🖼 Find the anime scene by image using your terminal

What Anime CLI ❓ ?? > This application is basically a ?? wrapper around trace.moe PREVIEW Usage ?? Get Anime By Image File ?? what-anime file anime.jp

Jan 2, 2023
Terminal stock ticker with live updates and position tracking
Terminal stock ticker with live updates and position tracking

Ticker Terminal stock watcher and stock position tracker Features Live stock price quotes Track value of your stock positions Support for multiple cos

Jan 8, 2023
lazyhub - Terminal UI Client for GitHub using gocui.
lazyhub - Terminal UI Client for GitHub using gocui.

lazyhub - Terminal UI Client for GitHub using gocui.

Dec 14, 2022
A modern and intuitive terminal-based text editor
A modern and intuitive terminal-based text editor

micro is a terminal-based text editor that aims to be easy to use and intuitive, while also taking advantage of the capabilities of modern terminals

Jan 7, 2023
Pi-hole data right from your terminal. Live updating view, query history extraction and more!
Pi-hole data right from your terminal. Live updating view, query history extraction and more!

Pi-CLI Pi-CLI is a command line program used to view data from a Pi-Hole instance directly in your terminal.

Dec 12, 2022
💻 PTerm | Pretty Terminal Printer A golang module to print pretty text
💻 PTerm | Pretty Terminal Printer A golang module to print pretty text

✨ PTerm is a modern go module to beautify console output. Featuring charts, progressbars, tables, trees, and many more ?? It's completely configurable and 100% cross-platform compatible.

Jan 1, 2023
A collection of terminal-based widgets for richer Golang CLI apps.
A collection of terminal-based widgets for richer Golang CLI apps.

Flinch A collection of terminal-based widgets for richer Golang CLI apps. Ships with a library to build your own widgets/TUIs too. Warning: This modul

Jan 7, 2023
A wrapper around cd and xdg-open to use aliases to directory paths in terminal

CDD - Change directories Dynamically I am a lazy linux user and turns out that basic tab completion wasn't enough for me to navigate through my direct

Dec 15, 2022
Terminal multiplexer inspired by i3

3mux is a terminal multiplexer with out-of-the-box support for search, mouse-controlled scrollback, and i3-like keybindings. Imagine tmux with a small

Dec 28, 2022
A simple terminal UI for Go linters
A simple terminal UI for Go linters

golintui golintui is a TUI tool that helps you run various kinds of linters with ease and organize its results, with the power of golangci-lint. Cool

Jun 9, 2022