Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

On AWS Linux

Not available as yum install on our current AMI. It should be on the latest AMI though: https://aws.amazon.com/amazon-linux-ami/2015.09-release-notes/

Installing from the source proved to be tricky.

Useful arguments

When running jq, the following arguments may become handy:

Argument Description
--version Output the jq version and exit with zero.
--sort-keys Output the fields of each object with the keys in sorted order.

Basic concepts

The syntax for jq is pretty coherent:

Syntax Description
, Filters separated by a comma will produce multiple independent outputs
? Will ignores error if the type is unexpected
[] Array construction
{} Object construction
+ Concatenate or Add
- Difference of sets or Substract
length Size of selected element
| Pipes are used to chain commands in a similar fashion than bash

Dealing with json objects

Description Command
Display all keys jq 'keys'
Adds + 1 to all items jq 'map_values(.+1)'
Delete a key jq 'del(.foo)'
Convert an object to array to_entries | map([.key, .value])

Dealing with fields

Description Command
Concatenate two fields fieldNew=.field1+' '+.field2

Dealing with json arrays

Slicing and Filtering

Description Command
All jq .[]
First jq '.[0]'
Range jq '.[2:4]'
First 3 jq '.[:3]'
Last 2 jq '.[-2:]'
Before Last jq '.[-2]'
Select array of int by value jq 'map(select(. >= 2))'
Select array of objects by value ** jq '.[] | select(.id == "second")'**
Select by type ** jq '.[] | numbers' ** with type been arrays, objects, iterables, booleans, numbers, normals, finites, strings, nulls, values, scalars

Mapping and Transforming

Description Command
Add + 1 to all items jq 'map(.+1)'
Delete 2 items jq 'del(.[1, 2])'
Concatenate arrays jq 'add'
Flatten an array jq 'flatten'
Create a range of numbers jq '[range(2;4)]'
Display the type of each item jq 'map(type)'
Sort an array of basic type jq 'sort'
Sort an array of objects jq 'sort_by(.foo)'
Group by a key - opposite to flatten jq 'group_by(.foo)'
Minimun value of an array jq 'min' .See also min, max, min_by(path_exp), max_by(path_exp)
Remove duplicates jq 'unique' or jq 'unique_by(.foo)' or jq 'unique_by(length)'
Reverse an array jq 'reverse'
@MuffintopSpeedos

This comment has been minimized.

Copy link

@MuffintopSpeedos MuffintopSpeedos commented Nov 7, 2018

s/cheet/cheat/g

Spellcheck...

@clhenrick

This comment has been minimized.

Copy link

@clhenrick clhenrick commented Nov 14, 2018

To select unique values of a property in an array of objects:

jq '[.[].property_name] | unique' data.json
@sky-marco-almeida

This comment has been minimized.

Copy link

@sky-marco-almeida sky-marco-almeida commented Dec 3, 2018

s/Minimun/Minimum/g

Spellcheck...

@brettwgreen

This comment has been minimized.

Copy link

@brettwgreen brettwgreen commented Jul 30, 2019

To select unique values of a property in an array of objects:

jq '[.[].property_name] | unique' data.json

👍

@wjmelements

This comment has been minimized.

Copy link

@wjmelements wjmelements commented Aug 15, 2019

To count the items in a subscripted array:

jq '.results | length'
@jsmucr

This comment has been minimized.

Copy link

@jsmucr jsmucr commented Oct 4, 2019

To flatten the whole JSON and turn it into a sorted key-value form:

[
    . as $in |
    (paths(scalars), paths((. | length == 0)?)) |
    join(".") as $key |
    $key + "=" + ($in | getpath($key | split(".") | map((. | tonumber)? // .)) | tostring)
] | sort | .[]
@aquelito

This comment has been minimized.

Copy link

@aquelito aquelito commented Dec 14, 2019

Dealing with features of featuresCollection

jq -c '{
type: .type, 
features: [
  .features[] | {
    type: .type,
    properties: .properties 
      | del(.REMOVE_SOME_KEY)
      | with_entries(.key |= ascii_downcase)
      | ( . += {
          "ADD_KEY": .ANOTHER_PROPERTIES_KEY
        })
      | del(.ANOTHER_PROPERTIES_KEY),
    geometry: .geometry
  }
]
}' "$PATH_TO_FILE" > $PATH_TO_NEW_FILE
@ImperadorSid

This comment has been minimized.

Copy link

@ImperadorSid ImperadorSid commented Apr 17, 2020

To select objects within arrays with regex:
jq '.animals[] | select(.genus | test("primates"))'

@danilogit

This comment has been minimized.

Copy link

@danilogit danilogit commented May 7, 2020

{ "myArray": [ { "key": "abc", "value": "123"}, { "key": "def", "value": "456"}, ]}

Hey! How can I replace only the value for the key "def" and return the same document changed?
Thanks,

@brettwgreen

This comment has been minimized.

Copy link

@brettwgreen brettwgreen commented May 7, 2020

{ "myArray": [ { "key": "abc", "value": "123"}, { "key": "def", "value": "456"}, ]}

This works... you kinda need to stream out the array elements, select and replace the value, repackage the array, and then repackage the json. Following example assumes your json is in test.json file

cat test.json | jq '{"myArray" : [.myArray[] | select(.key=="def").value = "999"]}'

Edit: This is cleaner without needing to 'repackage':

cat test.json | jq '(.myArray[] | select(.key=="def").value) = "999"'

@frankind

This comment has been minimized.

Copy link

@frankind frankind commented May 11, 2020

find unique keys in array

cat small.json | jq 'map(keys) | flatten | unique'
@frankind

This comment has been minimized.

Copy link

@frankind frankind commented May 15, 2020

Find Unique value with key name

cat data.json | jq 'map(.test_id) | flatten | unique'
@frankind

This comment has been minimized.

Copy link

@frankind frankind commented Jun 18, 2020

Merge two json array files

jq -s '[.[][]]' test1.json test2.json > result.json
@chb0github

This comment has been minimized.

Copy link

@chb0github chb0github commented Jul 1, 2020

vertically format output:

      jq -r '
        def width:      map(keys_unsorted | map(length) | max) | max ;
        def pad($w):    . + (($w-length)*" ") ;

        . | width as $w | map(to_entries | map("\(.key|pad($w)) : \(.value)"), [""]) | .[][]
      '

sample input:

 [
    {
      "StackId": "arn:aws:cloudformation:us-east-1:086524572673:stack/sonar-ops/51cd1b50-a5ed-11ea-ae38-0ee5b74c6229",
      "EventId": "0bc45ef0-a75c-11ea-aa5e-0a392ab5a299",
      "StackName": "sonar-ops",
      "LogicalResourceId": "sonar-ops",
      "PhysicalResourceId": "arn:aws:cloudformation:us-east-1:086524572673:stack/sonar-ops/51cd1b50-a5ed-11ea-ae38-0ee5b74c6229",
      "ResourceType": "AWS::CloudFormation::Stack",
      "Timestamp": "2020-06-05T18:40:36.433000+00:00",
      "ResourceStatus": "UPDATE_ROLLBACK_COMPLETE"
    }
 ]

sample output

StackId            : arn:aws:cloudformation:us-east-1:086524572673:stack/sonar-ops/51cd1b50-a5ed-11ea-ae38-0ee5b74c6229
EventId            : 0bc45ef0-a75c-11ea-aa5e-0a392ab5a299
StackName          : sonar-ops
LogicalResourceId  : sonar-ops
PhysicalResourceId : arn:aws:cloudformation:us-east-1:086524572673:stack/sonar-ops/51cd1b50-a5ed-11ea-ae38-0ee5b74c6229
ResourceType       : AWS::CloudFormation::Stack
Timestamp          : 2020-06-05T18:40:36.433000+00:00
ResourceStatus     : UPDATE_ROLLBACK_COMPLETE
@chb0github

This comment has been minimized.

Copy link

@chb0github chb0github commented Jul 1, 2020

Is there an opposite to del(.blah,.whatever) ? Like keep(.foo,.bar) if the list of keys to toss is large, it makes more sense to just state what you want to keep, not toss

@bfontaine

This comment has been minimized.

Copy link

@bfontaine bfontaine commented Aug 24, 2020

@chb0github yes:

$ echo '{"a":1, "b":2, "c":3, "d":4}' | jq '{b, d}'
{
  "b": 2,
  "d": 4
}
@pwillis-els

This comment has been minimized.

Copy link

@pwillis-els pwillis-els commented Dec 27, 2020

Given an array of dicts, sort them based on a version number, then output the unique dicts (based on some property) with the largest version number.

$ echo '[
             {   "name": "sample-a",
                 "version": "1.3" },
             {   "name": "sample-a",
                 "version": "2.5" },
             {   "name": "sample-a",
                 "version": "2.19" },
             {   "name": "sample-a",
                 "version": "1.0" },
             {   "name": "sample-b",
                 "version": "1.0" },
             {   "name": "sample-b",
                 "version": "1.1" },
             {   "name": "sample-b",
                 "version": "1.3" },
             {   "name": "sample-b",
                 "version": "1.20" }
         ]' | \
jq -r 'sort_by(.version | split(".") | map(tonumber) ) | reverse | unique_by(.name)'
[
  {
    "name": "sample-a",
    "version": "2.19"
  },
  {
    "name": "sample-b",
    "version": "1.20"
  }
]
@SVPA-LenPistoria

This comment has been minimized.

Copy link

@SVPA-LenPistoria SVPA-LenPistoria commented Feb 2, 2021

Is there any way to delete an object if it contains a particular key/value pair?

@baltakatei

This comment has been minimized.

Copy link

@baltakatei baltakatei commented Feb 8, 2021

Is there any way to delete an object if it contains a particular key/value pair?

Yes, with del and select:

$ cat example.json | jq '.'
{
  "myArray": [
    {
      "key": "abc",
      "value": "123"
    },
    {
      "key": "def",
      "value": "456"
    }
  ]
}
$ cat example.json | jq '. | del(  ."myArray"[] | select(."value" == "456")  )'
{
  "myArray": [
    {
      "key": "abc",
      "value": "123"
    }
  ]
}
@PsySc0rpi0n

This comment has been minimized.

Copy link

@PsySc0rpi0n PsySc0rpi0n commented Feb 11, 2021

Hello.
I have an array of objects with this form:

{
  "key1": "val1",
  "key2": "val2",
  "key3": "val3",
  "key4": val4,
  "status": "settled",
  "key_n": val_n,
}

I'm using the following command

jq '.forwards[] | select(.status == "settled")'

to get all the objects within an array, containing the following key:value pair:

status == "settled"

Now, I need to get all the values from the field "key4" from the previous output, like 1 per line or so.
Example:
If the previous command I used, return 150 objects, I want to return the value from the key "key4" from the 150 objects found with the previous command.
How can I filter this ?

@chb0github

This comment has been minimized.

Copy link

@chb0github chb0github commented Feb 11, 2021

I took your json, fixed the errors and copied it 150 times. Then applied as you asked

echo '
{
  "key1": "val1",
  "key2": "val2",
  "key3": "val3",
  "key4": "I am key 4",
  "status": "settled",
  "key_n": 10
}
' > foo.json
seq 1 150 | xargs -n 1 -I {} cp foo.json {}.json
jq -res '.[] | select(.status == "settled") | .key4' *.json

Which yields, as you request

...
I am key 4
I am key 4
I am key 4
I am key 4
I am key 4
I am key 4
I am key 4
I am key 4
I am key 4
...
@PsySc0rpi0n

This comment has been minimized.

Copy link

@PsySc0rpi0n PsySc0rpi0n commented Feb 11, 2021

I took your json, fixed the errors and copied it 150 times. Then applied as you asked

echo '
{
  "key1": "val1",
  "key2": "val2",
  "key3": "val3",
  "key4": "I am key 4",
  "status": "settled",
  "key_n": 10
}
' > foo.json
seq 1 150 | xargs -n 1 -I {} cp foo.json {}.json
jq -res '.[] | select(.status == "settled") | .key4' *.json

Which yields, as you request

...
I am key 4
I am key 4
I am key 4
I am key 4
I am key 4
I am key 4
I am key 4
I am key 4
I am key 4
...

Thanks a lot.
I think I should have been more specific. I'm sorry for this.

The wya this json object is, is the following:

{
    "forwards": [
        {
            "in_tunnel": "654593x532x0",
            "in_val": 80001801,
            "in_mval": "80001801mval",
            "status": "local_failed",
            "failcode": 4103,
            "failreason": "WIRE_TEMPORARY_TUNNEL_FAILURE",
            "received_time": 1604306055.435
        },
        {
            "in_tunnel: "654593x532x0",
            "in_val": 11672960,
            "in_mval": "11672960msat",
            "status": "local_failed",
            "failcode": 4103,
            "failreason": "WIRE_TEMPORARY_TUNNEL_FAILURE",
            "received_time": 1604307945.776
        },
        {
            "_hash": "7dcd278c2bbbf75cca7a68fb1eed9eaccbfbc3d4990fc7c532eb416144a6f9f3",
            "in_tunnel": "666334x1059x1",
            "out_ctunnel": "665969x1380x0",
            "in_val": 230352882,
            "in_mval": "230352882mval",
            "out_val": 230121761,
            "out_mval": "230121761mval",
            "fee": 231121,
            "fee_mval": "231121mval",
            "status": "settled",
            "received_time": 1611871705.477,
            "resolved_time": 1611871712.222
        }
    ]
}

So, this is just a small portion of the whole data. And I need to catch all blocks which have the key:value pair "status:settled" and then from those I need to "extract the "fee" key:value pairs.
The example you posted didn't work for me. I have this data now in a file for testing, but then, will be to be used through pipping.

Thank you for the example above.

Edited;
I also have to say that I only tried part of your example because I already have the data in a file.
I only used:
jq '.[] | select(.status == "settled") | .key4' my_data.json

@chb0github

This comment has been minimized.

Copy link

@chb0github chb0github commented Feb 11, 2021

christianb@christianb-mac ~ % jq -re '.forwards |= map(select(.status == "settled"))' deleteme.json 
{
  "forwards": [
    {
      "_hash": "7dcd278c2bbbf75cca7a68fb1eed9eaccbfbc3d4990fc7c532eb416144a6f9f3",
      "in_tunnel": "666334x1059x1",
      "out_ctunnel": "665969x1380x0",
      "in_val": 230352882,
      "in_mval": "230352882mval",
      "out_val": 230121761,
      "out_mval": "230121761mval",
      "fee": 231121,
      "fee_mval": "231121mval",
      "status": "settled",
      "received_time": 1611871705.477,
      "resolved_time": 1611871712.222
    }
  ]
}
echo '{
    "forwards": [
        {
            "in_tunnel": "654593x532x0",
            "in_val": 80001801,
            "in_mval": "80001801mval",
            "status": "local_failed",
            "failcode": 4103,
            "failreason": "WIRE_TEMPORARY_TUNNEL_FAILURE",
            "received_time": 1604306055.435
        },
        {
            "in_tunnel": "654593x532x0",
            "in_val": 11672960,
            "in_mval": "11672960msat",
            "status": "local_failed",
            "failcode": 4103,
            "failreason": "WIRE_TEMPORARY_TUNNEL_FAILURE",
            "received_time": 1604307945.776
        },
        {
            "_hash": "7dcd278c2bbbf75cca7a68fb1eed9eaccbfbc3d4990fc7c532eb416144a6f9f3",
            "in_tunnel": "666334x1059x1",
            "out_ctunnel": "665969x1380x0",
            "in_val": 230352882,
            "in_mval": "230352882mval",
            "out_val": 230121761,
            "out_mval": "230121761mval",
            "fee": 231121,
            "fee_mval": "231121mval",
            "status": "settled",
            "received_time": 1611871705.477,
            "resolved_time": 1611871712.222
        }
    ]
}
' | jq -re '.forwards |= map(select(.status == "settled"))'
{
  "forwards": [
    {
      "_hash": "7dcd278c2bbbf75cca7a68fb1eed9eaccbfbc3d4990fc7c532eb416144a6f9f3",
      "in_tunnel": "666334x1059x1",
      "out_ctunnel": "665969x1380x0",
      "in_val": 230352882,
      "in_mval": "230352882mval",
      "out_val": 230121761,
      "out_mval": "230121761mval",
      "fee": 231121,
      "fee_mval": "231121mval",
      "status": "settled",
      "received_time": 1611871705.477,
      "resolved_time": 1611871712.222
    }
  ]
}

in the future, please post valid json

@AlHood77

This comment has been minimized.

Copy link

@AlHood77 AlHood77 commented Feb 16, 2021

I have this command

kubectl get --context <my-context> svc --selector='my-selectors' --all-namespaces -o json |
jq -r '
.items
| [to_entries[]
   | {(.key+1|tostring): .value}
   | map_values(
      {Name:.metadata.name,
       Port:.spec.ports[0].port,
       Group: "group name",
       SSLMode: "prefer",
       MaintenanceDB: "postgres"})]
    | {Servers: .}'>file.json

which outputs:

{
  "Servers": [  
    {  
      "1": {
        "Name": "db-name",
        "Port": 5432,
        "Group": "group name",
        "SSLMode": "prefer",
        "MaintenanceDB": "postgres"
      }
    },  
    {
      "2": {
        "Name": "db-name",
        "Port": 3000,
        "Group": "group name",
        "SSLMode": "prefer",
        "MaintenanceDB": "postgres"
      }
    }
  ]
}

is it possible with jq to get it into this specific format?:

{
  "Servers": {
      "1": {
        "Name": "db-name",
        "Port": 5432,
        "Group": "group name",
        "SSLMode": "prefer",
        "MaintenanceDB": "postgres"
      },
      "2": {
        "Name": "db-name",
        "Port": 3000,
        "Group": "group name",
        "SSLMode": "prefer",
        "MaintenanceDB": "postgres"
      }
  }
}

Edit:
solved problem with:

kubectl get --context <my-context> svc --selector='my-selectors' --all-namespaces -o json |
jq -r '
.items
| [to_entries[]
   | {(.key+1|tostring): .value}
   | map_values(
      {Name:.metadata.name,
       Port:.spec.ports[0].port,
       Group: "group name",
       SSLMode: "prefer",
       MaintenanceDB: "postgres"})]
    | add
    | {Servers: .}'>file.json
@ericsonrumuy7

This comment has been minimized.

Copy link

@ericsonrumuy7 ericsonrumuy7 commented Apr 30, 2021

Merge multiple json file:

jq -s 'reduce .[] as $item ({}; . * $item)' *.json

@abrarcv170

This comment has been minimized.

Copy link

@abrarcv170 abrarcv170 commented May 21, 2021

find all occurrences of the key “SearchString” in json file and decrypt it's value from base64 using jq ,i have a complex json .i want to search for "SearchString" key (you can see that ,we can't use fixed index for it) and when the key appears decry-pt it's value from base64 (use something like @base64d),anyone can help me plz ? is this possible with jq?the input json given below

`[
{
"Name": "searchblock",
"Priority": 3,
"Statement": {
"RateBasedStatement": {
"Limit": 100,
"AggregateKeyType": "IP",
"ScopeDownStatement": {
"ByteMatchStatement": {
"SearchString": "Y2F0YWxvZ3NlYXJjaA==",
"FieldToMatch": {
"UriPath": {}
},
"TextTransformations": [
{
"Priority": 0,
"Type": "LOWERCASE"
}
],
"PositionalConstraint": "CONTAINS"
}
}
}
},
"Action": {
"Block": {}
},
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "searchblock"
}
},
{
"Name": "bot-block",
"Priority": 4,
"Statement": {
"ByteMatchStatement": {
"SearchString": "Ym90",
"FieldToMatch": {
"SingleHeader": {
"Name": "user-agent"
}
},
"TextTransformations": [
{
"Priority": 0,
"Type": "LOWERCASE"
}
],
"PositionalConstraint": "CONTAINS"
}
},
"Action": {
"Allow": {}
},
"VisibilityConfig": {
"SampledRequestsEnabled": true,
"CloudWatchMetricsEnabled": true,
"MetricName": "user-agent"
}
}
]``

i get solution from stackoverflow: https://stackoverflow.com/questions/67631286/decrypt-values-with-the-same-key-at-different-levels-from-base64

@juleslagarde

This comment has been minimized.

Copy link

@juleslagarde juleslagarde commented May 21, 2021

find all occurrences of the key “SearchString” in json file and decrypt it's value from base64 using jq ,i have a complex json .i want to search for "SearchString" key (you can see that ,we can't use fixed index for it) and when the key appears decry-pt it's value from base64 (use something like @base64d),anyone can help me plz ? is this possible with jq?the input json given below

[ { "Name": "searchblock", "Priority": 3, "Statement": { "RateBasedStatement": { "Limit": 100, "AggregateKeyType": "IP", "ScopeDownStatement": { "ByteMatchStatement": { "SearchString": "Y2F0YWxvZ3NlYXJjaA==", "FieldToMatch": { "UriPath": {} }, "TextTransformations": [ { "Priority": 0, "Type": "LOWERCASE" } ], "PositionalConstraint": "CONTAINS" } } } }, "Action": { "Block": {} }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "searchblock" } }, { "Name": "bot-block", "Priority": 4, "Statement": { "ByteMatchStatement": { "SearchString": "Ym90", "FieldToMatch": { "SingleHeader": { "Name": "user-agent" } }, "TextTransformations": [ { "Priority": 0, "Type": "LOWERCASE" } ], "PositionalConstraint": "CONTAINS" } }, "Action": { "Allow": {} }, "VisibilityConfig": { "SampledRequestsEnabled": true, "CloudWatchMetricsEnabled": true, "MetricName": "user-agent" } } ]

jq hasn't any function to decrypt base64
edit1: my bad there is @base64d as you said
edit2: @abrarcv170 here : (..|.SearchString? | select( . != null)) |= @base64d

@juleslagarde

This comment has been minimized.

Copy link

@juleslagarde juleslagarde commented May 21, 2021

Take key value json, split the key on '_' and recombine object (with the operator * (recusive merge))

[ . as $in | paths(scalars) as $opath | ($opath | map(split("_")) | flatten ) as $npath | {} | setpath($npath; ($in | getpath($opath)))] | reduce .[] as $item ({}; . * $item )

sample input

{
	"ansible_virtualization_role": "guest",
	"ansible_virtualization_type": "VMware",
	"ansible_distribution_release": "Core",
	"ansible_distribution_version": "7.7",
	"ansible_distribution_file_path": "/etc/redhat-release",
	"ansible_distribution_file_parsed": true,
	"ansible_distribution_file_variety": "RedHat"
}

sample output

{
  "ansible": {
    "virtualization": {
      "role": "guest",
      "type": "VMware"
    },
    "distribution": {
      "release": "Core",
      "version": "7.7",
      "file": {
        "path": "/etc/redhat-release",
        "parsed": true,
        "variety": "RedHat"
      }
    }
  }
}

link of the sample : https://jqplay.org/s/FXlektP2Jk

@chb0github

This comment has been minimized.

Copy link

@chb0github chb0github commented May 21, 2021

@juleslagarde - you can also use the // empty syntax

[
  {
    "Name": "searchblock",
    "Priority": 3,
    "Statement": {
      "RateBasedStatement": {
        "Limit": 100,
        "AggregateKeyType": "IP",
        "ScopeDownStatement": {
          "ByteMatchStatement": {
            "SearchString": "Y2F0YWxvZ3NlYXJjaA==",
            "FieldToMatch": {
              "UriPath": {}
            },
            "TextTransformations": [
              {
                "Priority": 0,
                "Type": "LOWERCASE"
              }
            ],
            "PositionalConstraint": "CONTAINS"
          }
        }
      }
    },
    "Action": {
      "Block": {}
    },
    "VisibilityConfig": {
      "SampledRequestsEnabled": true,
      "CloudWatchMetricsEnabled": true,
      "MetricName": "searchblock"
    }
  },
  {
    "Name": "bot-block",
    "Priority": 4,
    "Statement": {
      "ByteMatchStatement": {
        "SearchString": "Ym90",
        "FieldToMatch": {
          "SingleHeader": {
            "Name": "user-agent"
          }
        },
        "TextTransformations": [
          {
            "Priority": 0,
            "Type": "LOWERCASE"
          }
        ],
        "PositionalConstraint": "CONTAINS"
      }
    },
    "Action": {
      "Allow": {}
    },
    "VisibilityConfig": {
      "SampledRequestsEnabled": true,
      "CloudWatchMetricsEnabled": true,
      "MetricName": "user-agent"
    }
  }
]
jq '.[] | .. | .SearchString? // empty | @base64d' 
"catalogsearch"
"bot"
@marcelo321

This comment has been minimized.

Copy link

@marcelo321 marcelo321 commented May 23, 2021

How do I turn:

{
  "line": "abc",
  "lineNumber": "whatever"
}
{
  "line": "abc",
  "lineNumber": "aaaa"
}
{
  "line": "2222",
  "lineNumber": "asdasdqd"
}

into

[{
  "line": "abc",
  "lineNumber": "whatever"
},
{
  "line": "abc",
  "lineNumber": "aaaa"
},
{
  "line": "2222",
  "lineNumber": "asdasdqd"
}]
@chb0github

This comment has been minimized.

Copy link

@chb0github chb0github commented May 24, 2021

christianb@christianb-mac pcb % echo '{
  "line": "abc",
  "lineNumber": "whatever"
}
{
  "line": "abc",
  "lineNumber": "aaaa"
}
{
  "line": "2222",
  "lineNumber": "asdasdqd"
}' | jq -s .
[
  {
    "line": "abc",
    "lineNumber": "whatever"
  },
  {
    "line": "abc",
    "lineNumber": "aaaa"
  },
  {
    "line": "2222",
    "lineNumber": "asdasdqd"
  }
]
@chb0github

This comment has been minimized.

Copy link

@chb0github chb0github commented Jun 10, 2021

@49handyman you're going to have to explain better - given an input format x I need it to map to out y (y = f(x))

There is not a single bit of data in common between these two files.

@wjmelements

This comment has been minimized.

Copy link

@wjmelements wjmelements commented Jun 11, 2021

This thread is not a help forum. Please move your query elsewhere.

@chb0github

This comment has been minimized.

Copy link

@chb0github chb0github commented Jun 11, 2021

@wjmelements agreed. @49handyman delete your posts and give clear example input and clear example output. You can also try stack overflow

@49handyman

This comment has been minimized.

Copy link

@49handyman 49handyman commented Jun 11, 2021

i will try stack overflow, i didnt realize. i saw many posts so i asked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment