json tool - jq - as mentioned in Scripting Help

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
lmuserx4849

json tool - jq - as mentioned in Scripting Help

Post by lmuserx4849 »

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
xulstore.json
^^^^^^^^
1 compile error

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

Update:

Ahh, but jq . xulstore.json worked.
What's up with that?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29505
Joined: Wed Jul 06, 2011 3:58 am

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

Post by xenopeek »

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):
https://packages.ubuntu.com/xenial/libonig2
https://packages.ubuntu.com/xenial/jq
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.
Image
lmuserx4849

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

Post by lmuserx4849 »

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.
Locked

Return to “Scripts & Bash”