I have a multilevel json like so:
{"id": "id123","details": {"prod": "prod123","etype": "type1" },"accounts": [ {"bankName": "bank123","accountType": "account123","openingBalance": "bal123","fromDate": "2023-01-01","toDate": "2023-01-01","missingMonths": [],"transactions": [ {"dateTime": "2020-12-01","description": "a very long string","amount": -599.0,"bal": 8154.83,"type": "Debit" }, {"dateTime": "2020-12-01","description": "a very long string; a very long string","amount": -4000.0,"balanceAfterTransaction": 4154.83,"type": "Debit" } ] } ],"accountid": "sample123"}
I want to parse it to a csv in the following format:
id,prod,etype,bankName,accountType,openingBalance,fromDate,toDate,dateTime,description,amount,bal,type,accountidid123,prod123,type1,bank123,account123,bal123,2023-01-01,2023-01-01,2020-12-01,a very long string,-599.0,8154.83,Debit,sample123id123,prod123,type1,bank123,account123,bal123,2023-01-01,2023-01-01,2020-12-01,a very long string; a very long string,-4000.0,4157.83,Debit,sample123
Parse the transactions into a proper csv and repeat the common info for each transaction.
I have gotten only so far yet:
jq --raw-output '[ .id, .details[], .accounts[].transactions[] ]'