json tool - jq - as mentioned in Scripting Help

Forum rules
Before you post please read how to get help
Post Reply

json tool - jq - as mentioned in Scripting Help

Post by lmuserx4849 » Mon Jul 17, 2017 6:01 pm

In "Scripting Help", xenopeek said the data was json and install jq. I'd be interested in hearing about any tools of this type.

A json tool has been on my list for some time. I want to be able to read formatted json files, especially those created by firefox. I installed jq and read the help. The jq options used were "-Mr ":
  • -M: monochrome-output
  • -r: raw-output
Version: jq --version
jq version 1.3

I tried: jq -Mr xulstore.json

And got:

jq: Unknown option -Mr
Use jq --help for help with command-line options,
or see the jq documentation at http://stedolan.github.com/jq

I tried: jq -M -r xulstore.json and jq xulstore.json

And got:

error: xulstore is not defined
1 compile error

Any pointers would be appreciated to get me going in the right direction. Thank you.


Ahh, but jq . xulstore.json worked.
What's up with that?

User avatar
Level 24
Level 24
Posts: 24100
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: json tool - jq - as mentioned in Scripting Help

Post by xenopeek » Tue Jul 18, 2017 12:01 am

lmuserx4849 wrote:jq: Unknown option -Mr
Linux Mint 17.x has a very old version of jq but even if you are on that, it still supports those options according to the manual: http://manpages.ubuntu.com/manpages/tru ... /jq.1.html.

If you are on Linux Mint 17.x you may want to install the Linux Mint 18.x version of jq, which is the most recent release version. You can download the needed files for your architecture from (follow the amd64 link for 64 bit and the i386 link for 32 bit):
After downloading double-click the .deb files in your file browser to install them. Install libonig2 before jq.
lmuserx4849 wrote:I tried: jq -M -r xulstore.json and jq xulstore.json
As per the manual you are missing a filter in those commands. I.e., what is your query on the json data? At minimum you need the dot filter (just match everything):
jq -M -r . xulstore.json

I recommend reading the documentation, at least the basic filters section, at https://stedolan.github.io/jq/manual/. While you are narrowing down on the correct filter for your json data to get the information you need, you may want to not use the -M or -r options. -M makes output monochrome; that is friendly for scripts that parse jq output but less friendly for humans :wink: Leave colors on until you put the finished command into a script. Same for -r option that disables json quoting of values. Handy for scripts but until you have finished your filter leave it in place.
lmuserx4849 wrote:I'd be interested in hearing about any tools of this type.
Specifically json tools? A common named alternative to jq is rq: https://github.com/dflemstr/rq. I looked at it when I needed a tool that could handle optional elements, sort list elements and join them into a single line, and more. Wouldn't know how to start with that on rq but got it all working with jq's much more extensive documentation and examples.


Re: json tool - jq - as mentioned in Scripting Help

Post by lmuserx4849 » Wed Jul 19, 2017 2:28 am

Good stuff. Thank you. I'm going to have to spend some time playing with it. I am on 17.3. Interesting way to update software. I've been doing ppa's (yikes!), and a couple of appimage.

Post Reply

Return to “Scripts & Bash”