title: Scrapy's JSON output forms an array of JSON objects
body: <p>I'm trying to scrape a games info website using Scrapy. The scraping process goes like this: scraping the categories -&gt; scraping the list of games (multiple pages for each category) -&gt; scraping game info.
  The scraped info supposed to go into a json file. I'm getting the following result:</p>
  <pre class="lang-js prettyprint-override"><code>[
      {&quot;category&quot;: &quot;cat1&quot;, &quot;games&quot;: [...]},
      {&quot;category&quot;: &quot;cat2&quot;, &quot;games&quot;: [...]},
      ...
  ]
  </code></pre>
  <p>but I want to get this result:</p>
  <pre class="lang-js prettyprint-override"><code>{ &quot;categories&quot;:
      [
          {&quot;category&quot;: &quot;cat1&quot;, &quot;games&quot;: [...]},
          {&quot;category&quot;: &quot;cat2&quot;, &quot;games&quot;: [...]},
          ...
      ]
  }
  </code></pre>
  <p>I tried to use the steps from <a href="https://stackoverflow.com/questions/23490643/scrapy-returning-scraped-values-into-an-array">this post</a> and <a href="https://stackoverflow.com/questions/45158117/scrapy-creating-nested-json-object">this post</a>, with no success. couldn't find more related questions.</p>
  <p>I would appreciate any help.</p>
  <p>My spider:</p>
  <pre class="lang-py prettyprint-override"><code>import scrapy
  from ..items import Category, Game
  
  class GamesSpider(scrapy.Spider):
      name = 'games'
      start_urls = ['https://www.example.com/categories']
      base_url = 'https://www.exmple.com'
  
      def parse(self, response):
          categories = response.xpath(&quot;...&quot;)
  
          for category in categories:
              cat_name = category.xpath(&quot;.//text()&quot;).get()
              url = self.base_url + category.xpath(&quot;.//@href&quot;).get()    
              
              cat = Category()
              cat['category'] = cat_name
              
              yield response.follow(url=url, 
                                    callback=self.parse_category, 
                                    meta={ 'category': cat })
  
      def parse_category(self, response):
          games_url_list = response.xpath('//.../a/@href').getall()
  
          cat = response.meta['category']
          url = self.base_url + games_url_list.pop()
          next_page = response.xpath('//a[...]/@href').get()
          
          if next_page:
              next_page = self.base_url + response.xpath('//a[...]/@href').get()
  
          yield response.follow(url=url, 
                                callback=self.parse_game, 
                                meta={'category': cat, 
                                      'games_url_list': games_url_list, 
                                      'next_page': next_page})
              
      def parse_game(self, response):
          cat = response.meta['category']
          game = Game()
  
          try:
              cat['games_list']
          except:
              cat['games_list'] = []
          
          game['title_en'] = response.xpath('...')
          game['os'] = response.xpath('...')
          game['users_rating'] = response.xpath('...')
   
          cat['games_list'].append(game)
  
          games_url_list = response.meta['games_url_list']
          next_page = response.meta['next_page']
          
          if games_url_list: 
              url = self.base_url + games_url_list.pop()
              yield response.follow(url=url, 
                                    callback=self.parse_game, 
                                    meta={'category': cat, 
                                          'games_url_list': games_url_list, 
                                          'next_page': next_page})
  
          else:
              if next_page:
                  yield response.follow(url=next_page, 
                                        callback=self.parse_category, 
                                        meta={'category': cat})
              else:
                  yield cat
  </code></pre>
  <p>My item.py file:</p>
  <pre class="lang-py prettyprint-override"><code>import scrapy
  
  class Category(scrapy.Item):
      category = scrapy.Field()
      games_list = scrapy.Field()
  
  class Game(scrapy.Item):
      title_en = scrapy.Field()
      os = scrapy.Field()
      users_rating = scrapy.Field()
  </code></pre>