HackerTrans
TopNewTrendsCommentsPastAskShowJobs

wwader

no profile record

Submissions

Jaq 2.0 released with lots of improvements and support for jqjq

github.com
2 points·by wwader·vor 2 Jahren·0 comments

comments

wwader
·vor 3 Monaten·discuss
Assume input is an array you can do it several ways depending on what you want:

    # output each value in the array separately 
    .[]

    # output each value but transform it in some way
    .[] | . * 2


    # map each value into a new array
    map(. * 2) 

    # same as above but manual iterate/collect
    [.[] | . * 2]
wwader
·vor 11 Monaten·discuss
Same! and jq's regexp functions are quite powerful for transforming text into something more structured:

  $ echo -e "10:20: hello\n20:39: world" | jq -cR 'capture("^(?<timestamp>.*): (?<message>.*)$")'
  {"timestamp":"10:20","message":"hello"}
  {"timestamp":"20:39","message":"world"}


  $ echo -e "10:20: hello\n20:39: world" | jq -Rn '[inputs | capture("(?<t>.*): (?<m>.*)$").m] | join(" ")'
  "hello world"
Also using inputs/0 etc in combination with reduce and foreach it's possible to process streams of text that might not end.
wwader
·letztes Jahr·discuss
Very nice! thanks for building this
wwader
·letztes Jahr·discuss
The jaq author is working on a formal specification of jq https://github.com/01mf02/jq-lang-spec. I think it has also help that there are several implementations of jq now like, gojq, jaq and jqjq, that has helped finding edge cases and weird behaviours.
wwader
·letztes Jahr·discuss
The sqlite source includes a CLI tool called showdb that is quite nice for poking around in database files
wwader
·vor 2 Jahren·discuss
Note on (b): As i understand it JSONPath by design is limited to only be able to select things from the input, so can't build a new object, array etc.
wwader
·vor 2 Jahren·discuss
open -a is nice, i use it with alias, ex:

  alias qt='open -a "quicktime player"'
  alias vlc='open -a "vlc"'
wwader
·vor 2 Jahren·discuss
Yeap the syntax and semantics is quite different to other languages and it really took me a long time and deep understanding to really appreciate how expressive and damn well designed it is.
wwader
·vor 2 Jahren·discuss
As a heavy jq user and now a days also maintainer i say welcome! happy to help if you run into some problem
wwader
·vor 2 Jahren·discuss
Yeap love things like that, ex https://www.imdb.com/title/tt1787791/ and the mystery show podcast. Let me know if you know any!
wwader
·vor 2 Jahren·discuss
Reminds me of the documentary Kim's video https://www.imdb.com/title/tt24132144/ recommended!
wwader
·vor 2 Jahren·discuss
I think the alpine package format do use this in combination with tar being similar https://wiki.alpinelinux.org/wiki/Apk_spec
wwader
·vor 2 Jahren·discuss
Nice haven't seen. Shameless plug fq support elf https://github.com/wader/fq and will have a look if i could lend some ideas from llvm-readelf
wwader
·vor 2 Jahren·discuss
I once dumped a cassandra cluster to json (10ish gb i if remember correctly) and used jq to do queries
wwader
·vor 2 Jahren·discuss
Comparison of last example from https://axel.leroy.sh/quick-refs#dasel

desel: .data.all().filterOr(moreThan(.quantity,3),equal(.quantity,3)).mapOf(key,key,quantity,quantity)

yq: .data[] | select(.quantity >= 3) | {"key": .key, "quantity": .quantity}

jq: .data[] | select(.quantity >= 3) | {key, quantity}
wwader
·vor 2 Jahren·discuss
Hey! thanks for the jqjq shoutout!
wwader
·vor 2 Jahren·discuss
> Oh oh, jq has bugs..., I hope you reported them. I wondered more than once whether I could trust the results of my jq invocations.

Yes report, and i'm one of the jq maintainers now a days :) and i think you can trust the result if your doing common things. The bugs i've encountered have usually been in exotic parts, ex https://github.com/jqlang/jq/issues/3128
wwader
·vor 2 Jahren·discuss
No sure what your talking about, i get happy every time i get to use jq! :)
wwader
·vor 2 Jahren·discuss
Yes it is! see the example in the readme how to run jqjq with jqjq. Sadly you will probably need a lot of memory, it used to work on my laptop but not anymore after some recent changes that seem to have increased memory use.
wwader
·vor 2 Jahren·discuss
"thanks" :)