Convert Large number of mysql records to json using php

I want to convert LARGE NUMBER of MySQL data to JSON using PHP. I have 20K and above records but I am unable to convert MySQL data to JSON. I want to create REST API so need to send(response) data in JSON format.