Escape field name in jq that contains ‘@’ and ‘-‘? [duplicate]
You just need to quote the key: $ echo ‘…’ | jq ‘.abc.”@def-ghi”‘ “value1”
You just need to quote the key: $ echo ‘…’ | jq ‘.abc.”@def-ghi”‘ “value1”
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
[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
From the docs: jq ‘.[] | select(.id == “second”)’ Input [{“id”: “first”, “val”: 1}, {“id”: “second”, “val”: 2}] Output {“id”: “second”, “val”: 2} I think you can do something like this: jq ‘.theList[] | select(.id == 2 or .id == 4)’ array.json
When a key contains characters that are invalid for identifiers, you’ll have to quote the name. .”OPEN.BTC” Or for older versions of jq, use an index. .[“OPEN.BTC”] Example … | jq ‘.”OPEN.BTC”‘
You could try: jq -r ‘to_entries|map(“\(.key)=\(.value|tostring)”)|.[]’ test.json Here’s a demo: $ cat test.json { “var”: 1, “foo”: “bar”, “x”: “test” } $ jq -r ‘to_entries|map(“\(.key)=\(.value|tostring)”)|.[]’ test.json foo=bar var=1 x=test
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
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
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
jq has the fromjson builtin for this: jq ‘.c | fromjson | .id’ myFile.json fromjson was added in version 1.4.