I have a json file 'OpenEnded_mscoco_val2014.json'.The json file contains 121,512 questions.
Here is some sample :
"questions": [
{
"question": "What is the table made of?",
"image_id": 350623,
"question_id": 3506232
},
{
"question": "Is the food napping on the table?",
"image_id": 350623,
"question_id": 3506230
},
{
"question": "What has been upcycled to make lights?",
"image_id": 350623,
"question_id": 3506231
},
{
"question": "Is this an Spanish town?",
"image_id": 8647,
"question_id": 86472
}
]
I used jq -r '.questions | [map(.question), map(.image_id), map(.question_id)] | @csv' OpenEnded_mscoco_val2014_questions.json >> temp.csv
to convert json into csv.
But here output in csv is question followed by image_id which is what above code does.
The expected output is :
"What is table made of",350623,3506232
"Is the food napping on the table?",350623,3506230
Also is it possible to filter only results havingimage_id <= 10000
and to group questions having same image_id
? e.g. 1,2,3 result of json can be combined to have 3 questions, 1 image_id, 3 question_id.
EDIT : The first problem is solved by possible duplicate question
.I would like to know if is it possible to invoke comparison operator on command line in jq for converting json file. In this case get all fields from json if image_id <= 10000
only.