When consulting a API
I get the following JSON
:
{
"Count": 1,
"Data": [
{
"BlockedCount": 0,
"BouncedCount": 0,
"ClickedCount": 0,
"DeferredCount": 0,
"DeliveredCount": 0,
"HardBouncedCount": 0,
"LastActivityAt": "",
"OpenedCount": 0,
"PreQueuedCount": 0,
"ProcessedCount": 0,
"QueuedCount": 0,
"SenderID": 69059,
"SoftBouncedCount": 0,
"SpamComplaintCount": 0,
"UnsubscribedCount": 0,
"WorkFlowExitedCount": 0
}
],
"Total": 1
}
And I need to generate a file. CSV
with the following info:
"Count","BlockedCount","BouncedCount","ClickedCount","DeferredCount","DeliveredCount","HardBouncedCount","LastActivityAt","OpenedCount","PreQueuedCount","ProcessedCount","QueuedCount","SenderID","SoftBouncedCount","SpamComplaintCount","UnsubscribedCount","WorkFlowExitedCount","Total"
"1","0","0","0","0","0","0"," ","0","0","0","0","69059","0","0","0","0","1"
Where the first line are the labels of the data and the second line the values for each one of them.
I'm trying to generate this using jq but I'm still not getting it, my biggest difficulty is when dealing with the element. Data
which is an array of an element, but inside it has a format JSON
:
"Data": [
{
"BlockedCount": 0,
"BouncedCount": 0,
"ClickedCount": 0,
"DeferredCount": 0,
"DeliveredCount": 0,
"HardBouncedCount": 0,
"LastActivityAt": "",
"OpenedCount": 0,
"PreQueuedCount": 0,
"ProcessedCount": 0,
"QueuedCount": 0,
"SenderID": 69059,
"SoftBouncedCount": 0,
"SpamComplaintCount": 0,
"UnsubscribedCount": 0,
"WorkFlowExitedCount": 0
}
],
If I filter it in this way js .Data[0]
I get the output in JSON:
{
"BlockedCount": 0,
"BouncedCount": 0,
"ClickedCount": 0,
"DeferredCount": 0,
"DeliveredCount": 0,
"HardBouncedCount": 0,
"LastActivityAt": "",
"OpenedCount": 0,
"PreQueuedCount": 0,
"ProcessedCount": 0,
"QueuedCount": 0,
"SenderID": 69059,
"SoftBouncedCount": 0,
"SpamComplaintCount": 0,
"UnsubscribedCount": 0,
"WorkFlowExitedCount": 0
}
But I still do not know how I can put everything together, I would appreciate some help.