4 ms·
Having used https://jqlang.github.io/jq/ https://jqlang.github.io/jq/, wondering your pitch on advantages, alternative use cases for using fx?
by jspeaks 3y ago
Having used https://jqlang.github.io/jq/ https://jqlang.github.io/jq/, wondering your pitch on advantages, alternative use cases for using fx?
- deleted 3y ago[deleted]
- tetris11 3y agoNot OP but echo '{"name": "world"}' | fx 'x => x.name' 'x => `Hello, ${x}!`' Is immediately grokkable compared to jq's syntax. I love jq, I think it's extremely powerful, but I have to load up the documentation in a side window every time I have use it.
- jq_foo 3y agoEquivalent jq seems okay here: echo '{"name": "world"}' | jq '"Hello \(.name)"'
- medv 3y agoYes and both can be expressed in js and jq. Poinjt is what JS is known by much more peopel. As fx uses Node or Deno we for example can use lodash in fx: fx '_.groupBy("commit.author.name")' '_.mapValues(size)' '_.toPairs' '_.sortBy(1)' '_.reverse' '_.take(10)' '_.fromPairs' To do if in jq, it will take me much more time and extensive documentation reading.
- gcr 3y agoWhat’s the original JSON? Happy to try and express this in jq
- maleldil 3y agoLooks like the GitHub API: https://docs.github.com/en/free-pro-team@latest/rest/commits/commits?apiVersion=2022-11-28#list-commits https://docs.github.com/en/free-pro-team@latest/rest/commits... I'm looking forward to your jq version. I love jq and use it all the time, but for anything of that complexity, I'd probably just use Python.
- wwader 3y agoIf the task was the produce an object with the top 10 commiters with username as key and value number of commits maybe something liket this: group_by(.commit.author.name) | map({key: first.commit.author.name, value: length}) | sort_by(.value) | reverse[:10] | from_entries
- lucideer 3y agojq seems shorter but I don't see how it's more intuitive - ".name" is pretty basic jq syntax but how do I know \() is syntax for wrapping selectors within strings? I've used jq for many years and tbh I've never done string templating with it, so I would need to go digging in the docs. You can argue that's the case for any language, but it's the fundamental reason DSLs rarely capture the mainstream for on-the-fly utilities. Leveraging existing knowledge of a more heavily used syntax really helps here. Look at awk for example - it's been around forever, and despite its power and ubiquity in OS installs, you'll still see sed in many many more bash scripts because it's leaning on widely used familiar syntax rather than a DSL. That said - the fx example has "x => Hello, ${x}!" where I would expect "x => `Hello, ${x}!`", so that does indicate to me that fx has its own gotchas lurking - this example could just be contrived to look intuitive.
- umvi 3y agojq is YADSL though vs JS which is ubiquitous. Same reason most people can't use awk or sed.
- Etheryte 3y agoAs someone who doesn't use jq, a number of questions immediately jump out at me. Why is the input string double qouted ('"input"')? What does the backslash annotate? At first it looks like an escape similar to regex, but the other bracket doesn't have it so it must mean something else? Etc. Of course I could look the answers up, but the point is I can't tell without looking it up. While the code is short it feels similar to Awk, if you know it it's trivial, if you don't know it it's hard to be sure what it does without trying it out.
- markstos 3y agoI know JavaScript, so I immediately know a lot of the `fx` syntax. I always found the `jqc
- markstos 3y agoI know JavaScript, so I immediately know a lot of the `fx` syntax. I always found the `jq` syntax required many round-trips to the mail and more trial and error to get the syntax right.
- sghiassy 3y agoHappy jq user as well. But is jq interactive?
- TymekDev 3y agoijq [1] is. I am using it almost every time I need to come up with a jq expression. However, it gets noticeably laggy with enormous JSONs. [1]: https://sr.ht/~gpanders/ijq/ https://sr.ht/~gpanders/ijq/
- freedomben 3y agojq is probably better if you don't have node or deno installed since fx can't do expressions without it