John Chase John Chase - 7 months ago 27
PHP Question

PHP to Return Raw JSON Data?

I've been working on an tool that displays information from an API using PHP. Up until now I've been trying to echo individual fields of information one at a time in order to format them. Now I'm curious is it possible for me to somehow return just the whole unparsed JSON return, by this I mean just the raw JSON as it it. Can I somehow call that into a PHP page?

Here's an example of the JSON I'm referring to..

https://api.data.gov/sam/v4/registrations/7800853870000?return_values=full&api_key=CCHRrZMMc1s9I1dxtk4bwTPdoT4A1Xjck9w4Lii0

Answer

If you just want to output the json from https://api.data.gov/sam/v4/registrations/... on your website, you can use:

header('Content-Type: application/json');
$url = "https:///someJsonUrl";
echo file_get_contents($url);