I have a JSON data like this:
[ { "tone_id": "anger", "score": 0.012, "tone_name": "Anger" }, { "tone_id": "disgust", "score": 0.002, "tone_name": "Disgust" }, { "tone_id": "fear", "score": 0.14, "tone_name": "Fear" }, { "tone_id": "joy", "score": 0.42, "tone_name": "Joy" } ] I want to convert it into something like the following using jq:
{ "anger": 0.012, "disgust": 0.002, "fear": 0.14, "joy": 0.42 } Best I could do is:
cat result.json | jq '.[] | { (.tone_id): .score }' which gave the following:
{ "anger": 0.012 } { "disgust": 0.002 } { "fear": 0.14 } { "joy": 0.42 } I know I can easily do this using other methods. Just wanted to know if it's possible using
jqone-liner?
tone_idand their respectivescores... I want as many keys in my final object as the number of elements in the original list.tone_idandscoreand make them key, value respectively in the final output. I've added more concrete example above.