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·há 2 anos·0 comments

comments

wwader
·há 3 meses·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
·há 11 meses·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
·ano passado·discuss
Very nice! thanks for building this
wwader
·ano passado·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
·ano passado·discuss
The sqlite source includes a CLI tool called showdb that is quite nice for poking around in database files
wwader
·há 2 anos·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.