Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
The reason the output does not match is because jq's @uri function converts any reserved URI characters to their percent-encoded form. So while it constructs a URI given JSON data, it also (properly) encodes them. It you want to output a non-encoded URI, something like this will work.
It splits all key/value pairs into their own hash, which can then be "mapped" over, collecting each key/value and using a format string "key=value." Finally, join the resulting strings with an '&' character.
As an aside, I'd recommend really studying the jq manual--you'll discover all sorts of neat things you can do.
Last edited by individual; 01-08-2020 at 06:16 AM.
I think better to solve it with perl/python or probably awk.
Python can yes. After some searching, I can write a small program to encode / decode (I put a example below). I was hoping to glean some info too though from jq that the manual was being confusing about.
As an aside, I'd recommend really studying the jq manual--you'll discover all sorts of neat things you can do.
Yes, I referenced the manual but I suppose I got caught up on the @uri part.
the to_entries and -r --raw-input are both very helpful
I see to_entries does the following, which I assume lets it do its thing. I got confused since simply inputting it works, and shows it formatted pretty.
jq seems to be like awk where it has its own sublanguage
In a way, yes, but it is a domain specific language (DSL) because it primarily operates on JSON data (though it is possible to pass non-JSON data), whereas awk works with any text.
Quote:
EDIT:
Is it possible for jq to parse a query uri?
Could you elaborate?
EDIT: Assuming you're asking if jq can take a formatted URI and turn it into an object, then yes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.