title: formatting JSON created by scraping a website with Python and Scrapy
body: <p>I scraped a website using Scrapy and Python and managed to save the output into a JSON file with this command:</p>
  
  <pre><code>$ scrapy crawl wcr -o top_selling_beans.json -t json
  $ cat top_selling_beans.json 
  [{"price": "$17.75", "bean_name": "Espresso Torro"},
  {"price": "$18.75", "bean_name": "Sulawesi Toarco AA Tana Toraja"},
  {"price": "$17.75", "bean_name": "Costa Rica La Minita"},
  {"price": "$17.75", "bean_name": "Guatemala Acatenango Finca El Carmen"},
  {"price": "$18.25", "bean_name": "Ethiopia Dry-Process Yirga Cheffe Konga"}]
  </code></pre>
  
  <p>My only complaint is that I want "bean_name" to appear before "price".</p>
  
  <p>This is what is in my items.py file:</p>
  
  <pre><code>from scrapy.item import Item, Field
  
  class WestCoastRoastingItem(Item):
      bean_name = Field()
      price = Field()
  </code></pre>
  
  <p>This is the code for my spider:</p>
  
  <pre><code>from scrapy.spider import BaseSpider
  from scrapy.selector import Selector
  
  from westcoastroasters.items import WestCoastRoastingItem
  
  class WCRSpider(BaseSpider):
    name = "wcr"
    start_urls = ["http://www.westcoastroasting.com"]
  
    def parse(self, response):
      # Pull out the names and prices for the top sellers
      sel = Selector(response)
      top_sellers = sel.xpath(
        '//div[@id="SideTopSellers"]/div[@class="BlockContent"]/ul/li/div[@class="ProductDetails"]'
      )
      bean_names = top_sellers.xpath('strong/a/text()').extract()
      bean_prices = top_sellers.xpath('div[@class="ProductPriceRating"]/em/text()').extract()
  
      # Pass data to items
      items = []
      for name, price in zip(bean_names, bean_prices):
        item = WestCoastRoastingItem()
        item['bean_name'] = name
        item['price'] = price
        items.append(item)
      return items
  </code></pre>
  
  <p>Of course, maybe I am being too picky?  Does the order of the key-value pair in a JSON file make any real difference?  If so, how can I have the output look like so:</p>
  
  <pre><code>[{ "bean_name": "Espresso Torro", "price": "$17.75"}]
  </code></pre>
  
  <p>Thanks.</p>