3

So there is that awesome tool for working with JSON data called jq.

And there is that awesome linux file manager called mc.

One day (today) I came around an idea to integrate these two, so I could easily preview JSON files in a pretty/formatted way using F3 keyboard shortcut when in Midnight Commander.

I opened MC extension file using CommandEdit extension file menu actions and then added following to such opened configuration file:

# json
regex/\.json$
   View=%view{ascii} jq < %f

I thought it is straightforward, but unexpectedly it does not work: trying to view the JSON (F3) results in error popup with contents of jq's help page (the same as when you type jq by itself), so starting with: "jq - commandline JSON processr [version 1.5]..."

Can anybody tell me why this configuration is incorrect?

roomcays
  • 883
  • 1
  • 7
  • 19

2 Answers2

5

Two minutes after I submitted my question I've been revealed.

I thought that maybe jq does not produce standard output... It led me to this question: How to use jq in a shell pipeline? and so I have modified the extension file to look like:

# json
regex/\.json$
    View=%view{ascii} jq '.' < %f

And now it works as expected, piping result of jq to the internal mc viewer.

Thank you, me ;)

roomcays
  • 883
  • 1
  • 7
  • 19
0

You don't have to use redirection < here, you could use just a plain filename %f:

# json
regex/\.json$
    View=%view{ascii} jq '.' %f

and as you mentioned you have to use a simple filter: .

DIG mbl
  • 103
  • 6