title: How to save JSON pages iteratively from POST response?
body: <p>I am working with a JSON web-service where I am receiving a number of records in batches, only up to 100 at a time. There are parameters in my response which show if there are more than 100 records per request sent.  If there are, my logic calls the service again and dynamically changes the request.  My question is, how can I save EACH response, and not the last one called.</p>
  
  <p>Here is my script: </p>
  
  <pre><code>f2 =open('C:\Users\GeoffreyWest\Desktop\ContainerRequest.json')
  data2 = jsonpickle.decode((f2.read()))
  #do stuff for data2
  data2 = jsonpickle.encode(data2)
  lastpage = 'false'
  startrow = 0
  newquery = 'new'
  pagesize = 100
  
  url2 = "URL"
  headers2 = {'Content-type': 'text/plain', 'Accept': '/'}
  
  while lastpage == 'false':
      r2 = requests.post(url2, data=data2, headers=headers2)
      print r2.text
      decoded2 = json.loads(r2.text)
      f2 =open('C:\Users\GeoffreyWest\Desktop\ContainerRequest.json')
      data2 = jsonpickle.decode((f2.read()))
      if decoded2['Response']['LastPage'] == 'false':
          data2['QueryRequest']['PageSize'] = pagesize
          startrow = startrow + data2['QueryRequest']['PageSize']
          data2['QueryRequest']['StartRowNum'] = startrow
          data2['QueryRequest']['NewQuery'] = 'false'
          data2 = jsonpickle.encode(data2)
          print startrow
      else:
          lastpage = 'true'
  </code></pre>
  
  <p>Sample Request:</p>
  
  <pre><code>{
      "MetaData": {},
      "QueryRequest": {
          "LastUpdatedDate": "06/29/2015 13:00:00",
          "srType": [
              "Bulky Items",
              "Electronic Waste",
              "Metal/Household Appliances",
              "Dead Animal Removal",
              "Manual Pickup",
              "Brush Items Pickup",
              "Move In/Move Out",
              "Illegal Dumping Pickup"
  
          ],
          "NewQuery": "new",
          "PageSize": "100",
          "StartRowNum": "0"
      }
  }
  </code></pre>
  
  <p>Sample Response which requires loop to continue paging:</p>
  
  <pre><code>"Response": {
          "LastPage": "false",
          "NumOutputObjects": "100",
          "ListOfServiceRequest": {
  </code></pre>