Pagination for DB data


My requirement is to fetch the XXX records (Sometimes 100+) from DB, convert into json and send response thru setresponse as this is rest call. My question is how to achieve pagination for sending large amount of data in response? My Source is third party vendor and they want the response to be paginated in webmethods if the response data contains large amount of data.

Can someone please help me to how to achieve this? Do I need to write java service or Can I handle it in DB/setresponse calls?

You need to build your json response something similar to this? can you check with the client?

HTTP/1.1 200 OK
Content-Type: application/vnd.api+json

  "meta": {
    "totalPages": 13
  "data": [
      "type": "articles",
      "id": "3",
      "attributes": {
        "title": "JSON:API paints my bikeshed!",
        "body": "The shortest article. Ever.",
        "created": "2015-05-22T14:56:29.000Z",
        "updated": "2015-05-22T14:56:28.000Z"
  "links": {
    "self": "[number]=3&page[size]=1",
    "first": "[number]=1&page[size]=1",
    "prev": "[number]=2&page[size]=1",
    "next": "[number]=4&page[size]=1",
    "last": "[number]=13&page[size]=1"

Thank you…

Can you please explain a bit more , I thought of using documenttojsonstring and sending data thru setresponse. So where to use the above code If I want to paginate first 50 transaction in one page