Sunday, March 17, 2019

JQ the best Devops Json Processor tool

0 lượt xem comment 0 comments

JQ is a very powerful json processing tool. JQ is great because is written in C and is super fast. JQ also make json appear with a color highlight when you use it in Linux terminal. JQ is useful because you can combine with other DevOps tools like kubectl, docker, ectd, vault, and so on one. Basically, anything that returns a json output you can use JQ in order to process it. JQ has lots of interesting features and is possible to do pretty simple and yet powerful json processing. JQ allow us to subtract parts of the json document and also provide some powerful processing function like map, add, flatten and much more. It's possible to do some very high level and simple functional programming with it.


Now let's take a look on Sheet Cheat I made for JQ.

JQ Sheet Cheat

Install JQ

sudo apt-get install jq

Extract Field from Array

echo '[{"id":1,"name":"diego"},{"id":2,"name":"gandalfy"},{"id":3,"name":"melina"}]' | jq '.[:2]'
[
  {
    "id": 1,
    "name": "diego"
  },
  {
    "id": 2,
    "name": "gandalfy"
  }
]
echo '[{"id":1,"name":"diego"},{"id":2,"name":"gandalfy"},{"id":3,"name":"melina"}]' | jq '.[].name'
"diego"
"gandalfy"
"melina"
echo '[{"id":1,"name":"diego"},{"id":2,"name":"gandalfy"},{"id":3,"name":"melina"}]' | jq '.[].name'
"diego"
"gandalfy"
"melina"

Map Function

echo '[1,2,3]' | jq 'map(.+1)'
[
  2,
  3,
  4
]
echo '[12,14,15]' | jq 'map(.-2)'
[
  10,
  12,
  13
]

Add Function

echo "[1,2,3,4]" | jq add
10

Flatten Dunction

echo "[1, [2], [[3]]]" | jq flatten
[
  1,
  2,
  3
]

Max and Min

echo "[1, [2], [[3]]]" | jq flatten | jq max
3
echo "[1, [2], [[3]]]" | jq flatten | jq min
1

I hope you like it. Enjoy!

cheers,
Diego Pacheco
Tags: no keyword

comment 0 comments

Chuyên mục văn hoá giải trí của VnExpress

.

© 2017 www.blogthuthuatwin10.com

Tầng 5, Tòa nhà FPT Cầu Giấy, phố Duy Tân, Phường Dịch Vọng Hậu, Quận Cầu Giấy, Hà Nội
Email: nguyenanhtuan2401@gmail.com
Điện thoại: 0908 562 750 ext 4548; Liên hệ quảng cáo: 4567.