How to filter an array of objects based on values in an inner array with jq?

Very close! In your select expression, you have to use a pipe (|) before contains. This filter produces the expected output. . – map(select(.Names[] | contains (“data”))) | .[] .Id The jq Cookbook has an example of the syntax. Filter objects based on the contents of a key E.g., I only want objects whose genre … Read more

Using jq how can I split a very large JSON file into multiple files, each a specific quantity of objects?

[EDIT: This answer has been revised in accordance with the revision to the question.] The key to using jq to solve the problem is the -c command-line option, which produces output in JSON-Lines format (i.e., in the present case, one object per line). You can then use a tool such as awk or split to … Read more

How to get key names from JSON using jq

You can use: jq ‘keys’ file.json Complete example $ cat file.json { “Archiver-Version” : “Plexus Archiver”, “Build-Id” : “”, “Build-Jdk” : “1.7.0_07”, “Build-Number” : “”, “Build-Tag” : “”, “Built-By” : “cporter”, “Created-By” : “Apache Maven”, “Implementation-Title” : “northstar”, “Implementation-Vendor-Id” : “com.test.testPack”, “Implementation-Version” : “testBox”, “Manifest-Version” : “1.0”, “appname” : “testApp”, “build-date” : “02-03-2014-13:41”, “version” : … Read more

Modify a key-value in a json using jq in-place

Use a temporary file; it’s what any program that claims to do in-place editing is doing. tmp=$(mktemp) jq ‘.address = “abcde”‘ test.json > “$tmp” && mv “$tmp” test.json If the address isn’t hard-coded, pass the correct address via a jq argument: address=abcde jq –arg a “$address” ‘.address = $a’ test.json > “$tmp” && mv “$tmp” … Read more

Accessing a JSON object in Bash – associative array / list / another model

If you want key and value, and based on How do i convert a json object to key=value format in JQ, you can do: $ jq -r “to_entries|map(\”\(.key)=\(.value|tostring)\”)|.[]” file SALUTATION=Hello world SOMETHING=bla bla bla Mr. Freeman In a more general way, you can store the values into an array myarray[key] = value like this, just … Read more