I have a json response that I need to force to use https when on the live server.
So I need to detect if the response URL is using http or https.
If it's using http I need to switch it to https.
How can I force the header to use https?
The best way to handle this is when the user requests the JSON over HTTP, redirect it to HTTPS, and then the response will come back as HTTPS.
The Secure Pages module does just this. It will let you create regex patterns on paths, so you can have portions of your site use HTTPS, but not others. You would just need to add the paths for your JSON.
Note that the Drupal 7 version requires two patches against core, but I have clients who have these patches on live sites.