Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Equivalent jq seems okay here:

    echo '{"name": "world"}' | jq '"Hello \(.name)"'


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


What’s the original JSON? Happy to try and express this in jq


Looks like the GitHub API: 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.


If 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


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


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


Maybe the person you replied to fixed a syntax error in an edit? The backticks are required, and are currently in their comment.


After looking more at fx that seems to be the case yes! It's 100% pure js syntax so shouldn't have any gotchas.


jq is YADSL though vs JS which is ubiquitous. Same reason most people can't use awk or sed.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: