Skip to main content
Share Your Experience: Take the 2024 Developer Survey

New answers tagged

1 vote

Merging with JQ

Passing the "file 2" file first, then the "file 1" file, to the following jq expression, we perform a relational LEFT JOIN operation between the two. JOIN( INDEX(input[]; ....
Kusalananda's user avatar
  • 337k
1 vote
Accepted

data json to env unix with jq

The main issue in your initial attempts is that you set the environment variables in some other environment (the environment of the started sh shell in the first instance and the environment of the ...
Kusalananda's user avatar
  • 337k
8 votes
Accepted

How to use jq to get a value from two possible paths?

.b // .a.b This would extract the value of the top-level b key, but if that value is missing, null, or false (i.e, if the value is false in a boolean context), use the b key under a. The above would ...
Kusalananda's user avatar
  • 337k
0 votes

How to print path and key values of JSON file

The following answer is missing the precise syntax for the round-tripping we'd all like to see. But it makes up for that deficit with one additional feature: it's easy to memorize! $ cat ...
Erik Ostermueller's user avatar
1 vote
Accepted

Add \t to jq resulted array extraction

Here is the code that adds tabs before each line: jq '.array' file | sed '1!s/^/\t\t/' It adds \t\t before each line except the first one (if that's exactly what you wanted)
Amirreza's user avatar
  • 164
5 votes
Accepted

jq skip iteration over null

I would separate the pick() and the select() so that the correct languages are picked out first: pick(.subtitles["de","en-US","en"]) Then, select only the elements of ...
Kusalananda's user avatar
  • 337k
0 votes

jq: Printing multiple values from multiple arrays at once

Using Raku (formerly known as Perl_6) ~$ raku -MJSON::Tiny -e 'my %hash = from-json($_) given lines; my @a = %hash.values.map({ $_.values if $_{"list1"} }); ...
jubilatious1's user avatar
  • 3,335

Top 50 recent answers are included