-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add string parsing (builtin, test and doc). #373
Conversation
This is really cool! Since it's so specific to parsing URI query parameters, maybe the function should be named something more indicative of that? |
On the one hand, I'm going to use this a lot. On the other hand, I'm not sure this belongs on jq's standard library, although I certainly see the value of a "batteries included" approach. I agree with @nicowilliams in that changing the name would be nice. A few thoughts on this:
|
Thanks for these feedback and suggestions. I like the idea of this[that]=whatever into {"this": {"that": "whatever"}}... |
Please do NOT include this URL-parsing function as currently named and implemented. The name "parse" should be reserved for something as generic as parsing. Here is a list of some alternatives to consider for the "parse URL" function:
Each of these options naturally has its pros and cons. It may also be worthwhile considering more complete parsing of URLs, e.g. along the lines of http://api.jquerymobile.com/jQuery.mobile.path.parseUrl |
@pkoppstein Yes, I like a (On a related note, I'd like to have something like a URI template (RFC6570) facility in jq! Level 4 template support would be particularly awesome.) |
I'll review, and I may merge a version with your function renamed as discussed above. |
As noted in #439, the support jq now offers for regular expressions means we can for example parse URL-style "queries" very simply. Using capture/2 as defined in #439, the task becomes trivial:
For example:
Using jq's support for string interpolation, the above
|
I agree with @pkoppstein that parse_url is much less valuable now that capture/2 makes it easy to do this in a general way. The un-percent-encoding functionality in this PR may be useful in an external library if it can be translated to jq code. |
Well, I had to process such a log file... where a value from a JSON object was a query to our server.
...
{"date":"2014/03/05 15:25:42","ip":"81.83.144.50","query":"version=2014_02_20&language=nl&UUID=BE7FE9D9-83E1-4117-9ECF-69AEA4FF4124&dev=iPad3%2C3&os=7.0.6"}
{"date":"2014/03/05 15:27:43","ip":"91.183.33.9","query":"version=2014_02_20&language=fr&UUID=494018D1-6CAF-4D99-906B-088A9F9DCD02&dev=iPhone3%2C1&OS=7.0.6"}
...
Adding "parse" (somehow related to "split") made my processing more "natural"... I hope it helps. Thanks for creating jq.