title: How to convert Json file to CSV in python
body: <p>I am new to python and I would like to convert below Json file  to CSV file by using python.
  Please don't pass the whole json data in the code. Just pass the whole Json file in the code.</p>
  
  <pre><code>{
    "Breakfast": {
      "Brk_item1": "Milk",
      "Brk_item2": "Egg"
    },
    "Lunch": {
      "Lnc_item1": "Pasta",
      "Lnc_item2": "Sprouts"
    },
    "Dinner": {
      "Dnr_item1": "Pizza",
      "Dnr_item2": "Burger"
    }
  },
  
  {
    "Breakfast": {
      "Brk_item1": "Bread",
      "Brk_item2": "Butter"
    },
    "Lunch": {
      "Lnc_item1": "Indian Meal",
      "Lnc_item2": "Paratha"
    },
    "Dinner": {
      "Dnr_item1": "Roti",
      "Dnr_item2": "Paneer"
    }
  }
  </code></pre>
  
  <p>and my expected output will be like below in CSV format</p>
  
  <pre><code>Brk_item1   Brk_item2   Lnc_item1   Lnc_item2   Dnr_item1   Dnr_item2
  
  Milk        Egg         Pasta       Sprouts     Pizza       Burger
  
  Bread       Butter      Indian Meal Paratha     Roti        Paneer
  </code></pre>
  
  <p>This is what I have tried so far:</p>
  
  <pre class="lang-py prettyprint-override"><code>import json
  import csv
  with open("./sample.json") as file:
    data = json.load(file)
  
  fname="output.csv"
  
  with open(fname,"w") as file:
      csv_file = csv.writer(file)
      csv_file.writerow ([ "Brk_item1","Brk_item2","Lnc_item1","Lnc_item2","Dnr_item1","Dnr_item2"])
      for item in data["Breakfast"]:
          csv_file.writerow([item["Brk_item1"],item["Brk_item2"],item["Lnc_item1"],item["Lnc_item2"],item["Dnr_item1"],item["Dnr_item2"]])
  </code></pre>