A mini library to convert your response include header status code to JSON. This actually based on this gist but I modified parameter position and I want to use it as a library.
composer require satyakresna/json-response
Please find the usage on sample file