Bitmand

Data Formats

Markdown

JQ

JQ slurp

Convert lines of json objects to a json list using -s / --slurp:

# file.txt
{"id":1,"name":"Foo"}
{"id":2,"name":"Bar"}

$ cat file.txt | jq --slurp '.'
[
  {
    "id": 1,
    "name": "Foo"
  },
  {
    "id": 2,
    "name": "Bar"
  }
]

JQ select

Select all list elements matching Bar using select():

# file.txt
[{"id":1,"name":"Foo"},{"id":2,"name":"Bar"}]

$ cat file.txt | jq '. | select(.name=="Bar")'
[
  {
    "id": 2,
    "name": "Bar"
  }
]

Bitmand - a self-proclaimed Internet Enthusiast!