top | item 25519826

(no title)

schmooser | 5 years ago

I've been using jq for several years but still can't write anything more complex than simple XPath without going to manual and googling.

Babashka[1] with Cheshire[2] aliased as json solves this to me, the code is longer but no need for googling anymore:

  USERX='{"name":"duchess","city":"Toronto","orders":[{"id":"x","qty":10},{"id":"y","qty":15}]}'

  echo $USERX | jq '.orders[]|select(.qty>10)'
  {
    "id": "y",
    "qty": 15
  }

  echo $USERX | bb -i -o '(-> *input* first (json/decode true) (->> :orders (filter #(> (:qty %) 10))))'
  {:id y, :qty 15}

[1]: https://github.com/borkdude/babashka [2]: https://github.com/dakrone/cheshire

discuss

order

No comments yet.