0

Extend of this question: How to combine strings from JSON values, keeping only part of the string? Above link's output also include the "name" of folder type, need to exclude these "type":

           "date_added": "13170994909893393",
           "date_modified": "13184204204228233",
           "id": "2098",
           "name": "ElasticSearch",
           "sync_transaction_version": "1",
           "type": "folder"

How to get only field if "type" of the same object is "url", otherwise ignore:

A valid pattern that will be put in the output:

           "type": "url",
           "url": "https://url_here"
Tuyen Pham
  • 1,805

1 Answers1

2

Given an array of objects, jq can select the ones that fulfil a certain criteria using select().

It sounds like you may want to use

.array[] | select(.type == "url")

Given a JSON document like

{ "array": [ { "type": "folder", "name": "example folder" },
             { "type": "url",    "name": "example url"    } ] }

the above query will return

{
  "type": "url",
  "name": "example url"
}
Kusalananda
  • 333,661