Мне показалось, что я достаточно разбираюсь в jq, чтобы иметь возможность форматировать файлы .csv так, как я хочу, но всегда есть одна хитрость, которую я пропустил!.
Моя загрузка API выглядит следующим образом .. ..
{
"status": "ok",
"meta": {
"count": 4
},
"data": {
"1019761328": {
"achievements": {
"medalCarius": 1,
"medalHalonen": 3,
"aimer": 6,
"invader": 13,
"armorPiercer": 18,
"medalMonolith": 2,
"medalEkins": 1,
"medalKay": 2,
"duelist": 409,
"newMeritPM2": 1,
"readyForBattleLT": 4,
"defender": 15,
"readyForBattleATSPG": 4,
"medalLeClerc": 2,
"demolition": 112,
"supporter": 13,
"steelwall": 107,
"medalLehvaslaiho": 28,
"medalAbrams": 2,
"readyForBattleSPG": 4,
"medalPoppel": 1,
"medalPascucci": 68,
"reliableComrade": 303,
"NY19A1": 1,
"NY19A2": 1,
"tankwomen": 1,
"luckyDevil": 10,
"NY18A3": 1,
"NY18A2": 1,
"mainGun": 28,
"NY18A1": 1,
"sinai": 5,
"firstMerit": 1,
"medalOrlik": 8,
"bonecrusher": 824,
"titleSniper": 41,
"warrior": 5,
"ironMan": 130,
"huntsman": 2,
"even": 35,
"medalKolobanov": 1,
"scout": 4,
"beasthunter": 5,
"kamikaze": 30,
"02YearsOfService": 1,
"tankExpert2": 1,
"tankExpert1": 1,
"readyForBattleMT": 4,
"tankExpert7": 1,
"tankExpert6": 1,
"sniper2": 10,
"arsonist": 106,
"charmed": 194,
"medalBillotte": 1,
"fighter": 147,
"medalLavrinenko": 2,
"impenetrable": 155,
"sturdy": 65,
"NY19A3": 1,
"medalKursk": 1,
"soldierOfFortune": 4,
"handOfDeath": 4,
"DdaymarathonMedal": 1,
"shootToKill": 3029,
"medalDumitru": 3,
"evileye": 8,
"medalKnispel": 1
},
"frags": {
"crucialShotMedal": 0,
"prematureDetonationMedal": 0,
"sentinelMedal": 0,
"infiltratorMedal": 0,
"fightingReconnaissanceMedal": 0,
"fireAndSteelMedal": 0,
"rangerMedal": 0,
"reliableComrade": 29,
"pyromaniacMedal": 0,
"wolfAmongSheepMedal": 0,
"heavyFireMedal": 0,
"bruteForceMedal": 0,
"guerrillaMedal": 0,
"promisingFighterMedal": 0,
"beasthunter": 595,
"geniusForWarMedal": 0,
"sinai": 523,
"pattonValley": 62
},
"max_series": {
"armorPiercer": 18,
"aimer": 6,
"titleSniper": 41,
"deathTrack": 0,
"invincible": 3,
"victoryMarch": 0,
"EFC2016": 0,
"diehard": 6,
"WFC2014": 0,
"tacticalBreakthrough": 0,
"handOfDeath": 4
}
},
"1034967155": {
"achievements": {},
"frags": {
"crucialShotMedal": 0,
"prematureDetonationMedal": 0,
"sentinelMedal": 0,
"infiltratorMedal": 0,
"fightingReconnaissanceMedal": 0,
"fireAndSteelMedal": 0,
"rangerMedal": 0,
"reliableComrade": 0,
"pyromaniacMedal": 0,
"wolfAmongSheepMedal": 0,
"heavyFireMedal": 0,
"bruteForceMedal": 0,
"guerrillaMedal": 0,
"promisingFighterMedal": 0,
"beasthunter": 0,
"geniusForWarMedal": 0,
"sinai": 0,
"pattonValley": 0
},
"max_series": {
"armorPiercer": 0,
"aimer": 0,
"titleSniper": 0,
"deathTrack": 0,
"invincible": 0,
"victoryMarch": 0,
"EFC2016": 0,
"diehard": 0,
"WFC2014": 0,
"tacticalBreakthrough": 0,
"handOfDeath": 0
}
}
}
}
Мой вывод .csv должен содержать поле ID, поле Medal и поле # медалей и выглядеть следующим образом ....
1019761328,"medalCarius",1
1019761328,"medalHalonen",3
1019761328,"aimer",6
...... etc. repeated for every ID
Пока чтоэти команды удаляют нужные мне данные ....
jq -r '.data | to_entries[] | {id: .key, val: .value[]} '
, что приводит к ....
{
"id": "1019761328",
"val": {
"medalCarius": 1,
"medalHalonen": 3,
"aimer": 6,
"invader": 13,
"armorPiercer": 18,
"medalMonolith": 2,
"medalEkins": 1,
"medalKay": 2,
"duelist": 409,
"newMeritPM2": 1,
"readyForBattleLT": 4,
"defender": 15,
"readyForBattleATSPG": 4,
"medalLeClerc": 2,
"demolition": 112,
"supporter": 13,
"steelwall": 107,
"medalLehvaslaiho": 28,
"medalAbrams": 2,
"readyForBattleSPG": 4,
"medalPoppel": 1,
"medalPascucci": 68,
"reliableComrade": 303,
"NY19A1": 1,
"NY19A2": 1,
"tankwomen": 1,
"luckyDevil": 10,
"NY18A3": 1,
"NY18A2": 1,
"mainGun": 28,
"NY18A1": 1,
"sinai": 5,
"firstMerit": 1,
"medalOrlik": 8,
"bonecrusher": 824,
"titleSniper": 41,
"warrior": 5,
"ironMan": 130,
"huntsman": 2,
"even": 35,
"medalKolobanov": 1,
"scout": 4,
"beasthunter": 5,
"kamikaze": 30,
"02YearsOfService": 1,
"tankExpert2": 1,
"tankExpert1": 1,
"readyForBattleMT": 4,
"tankExpert7": 1,
"tankExpert6": 1,
"sniper2": 10,
"arsonist": 106,
"charmed": 194,
"medalBillotte": 1,
"fighter": 147,
"medalLavrinenko": 2,
"impenetrable": 155,
"sturdy": 65,
"NY19A3": 1,
"medalKursk": 1,
"soldierOfFortune": 4,
"handOfDeath": 4,
"DdaymarathonMedal": 1,
"shootToKill": 3029,
"medalDumitru": 3,
"evileye": 8,
"medalKnispel": 1
}
}
{
"id": "1019761328",
"val": {
"crucialShotMedal": 0,
"prematureDetonationMedal": 0,
"sentinelMedal": 0,
"infiltratorMedal": 0,
"fightingReconnaissanceMedal": 0,
"fireAndSteelMedal": 0,
"rangerMedal": 0,
"reliableComrade": 29,
"pyromaniacMedal": 0,
"wolfAmongSheepMedal": 0,
"heavyFireMedal": 0,
"bruteForceMedal": 0,
"guerrillaMedal": 0,
"promisingFighterMedal": 0,
"beasthunter": 595,
"geniusForWarMedal": 0,
"sinai": 523,
"pattonValley": 62
}
}
{
"id": "1019761328",
"val": {
"armorPiercer": 18,
"aimer": 6,
"titleSniper": 41,
"deathTrack": 0,
"invincible": 3,
"victoryMarch": 0,
"EFC2016": 0,
"diehard": 6,
"WFC2014": 0,
"tacticalBreakthrough": 0,
"handOfDeath": 4
}
}
{
"id": "1034967155",
"val": {}
}
{
"id": "1034967155",
"val": {
"crucialShotMedal": 0,
"prematureDetonationMedal": 0,
"sentinelMedal": 0,
"infiltratorMedal": 0,
"fightingReconnaissanceMedal": 0,
"fireAndSteelMedal": 0,
"rangerMedal": 0,
"reliableComrade": 0,
"pyromaniacMedal": 0,
"wolfAmongSheepMedal": 0,
"heavyFireMedal": 0,
"bruteForceMedal": 0,
"guerrillaMedal": 0,
"promisingFighterMedal": 0,
"beasthunter": 0,
"geniusForWarMedal": 0,
"sinai": 0,
"pattonValley": 0
}
}
{
"id": "1034967155",
"val": {
"armorPiercer": 0,
"aimer": 0,
"titleSniper": 0,
"deathTrack": 0,
"invincible": 0,
"victoryMarch": 0,
"EFC2016": 0,
"diehard": 0,
"WFC2014": 0,
"tacticalBreakthrough": 0,
"handOfDeath": 0
}
}
Как мне теперь получить это в нужном мне формате .csv?
Любая помощь будет принята с благодарностью - спасибо!