Questions tagged [jq]

20 questions
10
votes
1 answer

Extract element from JSON array with jq

I have the following JSON file inp.json: { "x": 0, "tx": [ { "id": "a", "t" : "t for a" }, { "id": "b", "t": "t for b" } ] } I would like to extract the value of the first occurance of the key "t" within "tx". I tried jq…
3
votes
2 answers

How to convert lscpu output to JSON format with no trailing spaces?

I tried to convert it to the JSON format by -J flag, but older lscpu versions have no such functionality. The solutions I've found here didn't help me. I want to put out here the solution I got from member of another community.
2
votes
1 answer

jq and array of two things: key and value

I have this script: curl -sX 'GET' \ 'https://api.coingecko.com/api/v3/exchange_rates' \ -H 'accept: application/json' | jq -rc '.[]|select(.)|keys,(.[].value|tostring)' and the source of the JSON is: { "rates": { "btc": { "name":…
pbies
  • 3,550
2
votes
2 answers

How can I make youtube-dl return the creator of a playlist?

I can use youtube-dl with the --dump-json option and jq to get the uploader of a video: uploader=$(youtube-dl --dump-json "$video_url" | jq -r '.uploader') Is there a way to get the creator of a playlist in a similar way? youtube-dl -j…
fuumind
  • 443
1
vote
1 answer

Failure to convert JSON to CSV file

I need to extract a particular anti-virus product scan results from a JSON file and list the elements in csv format for further processing. JSON file sample as below: Contents of a file scanresults.json { "scans": { "Bkav": { "detected":…
1
vote
1 answer

How do I uninstall a tool that was installed without a package manager on windows via git-bash?

Clarification: So my question is rather general and doesn't address a specific tool, however, my issue came as a consequence of the need to remove the tool jq. I would appreciate a more generic approach to address all tools but if not possible, then…
1
vote
1 answer

jq filtering - Cannot index array with string ""value"

I am trying to get the application name and print its corresponding apiDefinition for a specific key which is embedded in the value parameter. I get error "Cannot index array with string" As I am not very good at jq especially the nested json, need…
Rocky M
  • 11
1
vote
1 answer

Using jq with xargs

I have a json-file with n users. I need to replace the id-field with a different UUID for each user. After that, I need to make n curl calls with the json as payload. How can I achieve this? My json file: [{ "id": "a3d920e", "name": "Alice", …
1
vote
1 answer

Change one .json key value with an already existing one using jq

My test.json file contains the 2 keys: { "id": "123", "name": "John" } And I want to achieve something like this: { "id": "John" } where as you can see I change the value of the key id with the value of the key name. I'm guessing I…
Oscar
  • 13
1
vote
1 answer

cURL - use specific response header as part of the filename

I am using this bash command to write the json http response body into a file: curl -s "http://some.domain.com/getSomeJson" | jq . | tee someJson.json; But what I really want is something like this: curl -s "http://some.domain.com/getSomeJson" | jq…
kiltek
  • 141
1
vote
1 answer

Piping from youtube-dl to jq in command substitution

When I run youtube-dl -j "$youtube_url" | jq I get a nice json output. However, when I run json=$(youtube-dl -j "$youtube_url" | jq) then jq prints it's usage page and after that youtube-dl fails with a broken pipe error. The json-variable is…
fuumind
  • 443
1
vote
1 answer

Surround Field from JSON with quotes

I want to change a field in json from number to string format. I create the json output from a dynamical created text file like this: LastUpdate=2019-12-01T13:26:46.388817319+01:00 State=NOT…
Thomas
  • 176
1
vote
1 answer

Json Parsing with Jsonpath based on string condition filters

I am fairly new with Jsonpath and am forced to use due to a project dependency. The sample json loooks like this { "people": { "a": {"First":"James", "last": "d"}, "b": {"First":"Jacob", "last": "e"}, "c": {"First":"Jayden", "last":…
ram
  • 11
1
vote
2 answers

jq filtering - Cannot index array with string "Score"

I am trying to find person name who has a subject and it score. But i am getting index arrary. jq -r '.[] | select(.result."*value*".Score.English) | {Name: .result."*value*".name, Subject: .result."*value*".Score.English} | @text' test.txt | sed…
ABHi
  • 11
0
votes
1 answer

Better method to use jq

I have a JSON that looks like: { "LDAP": { "RemoteRoleMapping": [ { "LocalRole": "dirgroup234fe3432", "RemoteGroup": "CN=somethingelse,OU=another,OU=more,DC=my,DC=org" }, { "LocalRole":…
1
2