title: how to iterate through a json that has multiple pages
body: <p>I have created a program that iterates through a multi-page json object.</p>
  
  <pre><code>def get_orgs(token,url):
      part1 = 'curl -i -k -X GET -H "Content-Type:application/json" -H "Authorization:Bearer '
      final_url = part1 + token + '" ' + url 
      pipe = subprocess.Popen(final_url, shell=False,stdout=subprocess.PIPE,stdin=subprocess.PIPE)
      data = pipe.communicate()[0]
      for line in data.split('\n'):
          print line
          try:
              row = json.loads(line)
              print ("next page url ",row['next'])
          except :
              pass
      return row
  my_data = get_orgs(u'MyBeearerToken',"https://data.ratings.com/v1.0/org/576/portfolios/36/companies/")
  </code></pre>
  
  <p>The json object is as below:</p>
  
  <pre><code>[{results: [{"liquidity":"Strong","earningsPerformance":"Average"}]
  ,"next":"https://data.ratings.com/v1.0/org/576/portfolios/36/companies/?page=2"}]
  </code></pre>
  
  <p>I am using 'next' key to iterate,but at times it points to "Invalid Page" ( a page that doesn't exist). Does JSON object have a rule about how many records are there on each page ? In that case , I will use that to estimate how many pages are possible.</p>
  
  <p>EDIT: Adding more details
  The json has just 2 keys ['results','next']. If there are multiple pages, then the 'next' key has the next page's url (<code>as you can see in the output above</code>). Else , it contains 'None'. 
  But, problem is that at times, instead of 'None' , it points to the next page (which does not exist). So, I want to see if I can count the rows in Json and divide by a number to know how many pages the loop needs to iterate through.</p>