I have text from a JSON file in this format:
"Abomasnow": {"level": 86, "abilities": ["Snow Warning"], "items": ["Assault Vest", "Light Clay"], "roles": {"Bulky Support": {"abilities": ["Snow Warning"], "items": ["Assault Vest", "Light Clay"], "teraTypes": ["Ice", "Water"], "moves": ["Aurora Veil", "Blizzard", "Earthquake", "Ice Shard", "Wood Hammer"]}}},
"Alomomola": {"level": 87, "abilities": ["Regenerator"], "items": ["Leftovers", "Rocky Helmet"], "roles": {"Bulky Support": {"abilities": ["Regenerator"], "items": ["Leftovers", "Rocky Helmet"], "teraTypes": ["Steel"], "moves": ["Body Slam", "Liquidation", "Mirror Coat", "Protect", "Wish"]}}},
"Altaria": {"level": 88, "abilities": ["Natural Cure"], "items": ["Heavy-Duty Boots", "Leftovers"], "roles": {"Bulky Support": {"abilities": ["Natural Cure"], "items": ["Heavy-Duty Boots"], "teraTypes": ["Steel"], "moves": ["Brave Bird", "Defog", "Earthquake", "Haze", "Roost", "Will-O-Wisp"]}, "Bulky Setup": {"abilities": ["Natural Cure"], "items": ["Heavy-Duty Boots", "Leftovers"], "teraTypes": ["Flying", "Ground"], "moves": ["Brave Bird", "Dragon Dance", "Earthquake", "Roost"]}}},
There are hundreds of rows. I want to format this so it is more readable. Is there any way to do this with Python so it is not manual. Which will involve looping through each row, some of which are more complicated than others.
The output I want would be something like the following:
Abomasnow has the ability snow warning, can hold items assault vest, light clay, has the tera types ice or water, learns the moves Aurora Veil, Blizzard, Earthquake, Ice Shard, Wood Hammer.
Or could just be
Abomasnow, abilities snow warning, items assault vest or light clay, tera type ice or water, moves Aurora Veil, Blizzard, Earthquake, Ice Shard, Wood Hammer
Would this be at all possible, or would it be best just to remove all the brackets?
I have tried removing the brackets but still looks a bit bad. Not too sure how to proceed
You can write a function
pkmn_verbose_strto build a string using the data in the dictionary.Then use module
jsonfrom standard library to read the json file into a python dict, applypkmn_verbose_strto the items in that dict, and then write the resulting list of lines to a new text file.Or perhaps better suited to the structure of your data: