Outputing and parsing JSON from package to single page

Permalink
Here's the JSON:http://mcormc.co/api?action=feeds...

Here's the code behind that single page:

<?php defined('C5_EXECUTE') or die(_("Access Denied.")); header('Content-Type: application/json'); echo $json_from_custom_page_controller; ?>


The JSON that outputs there is good: I can parse the same data from a_static_file.json to a single page installed through a custom concrete5 package. I can't figure out why I can't parse the data directly. I suspect that the problem could draw from the content-type. Any suggestion here would be appreciated.

In a a custom package's controller or single_page folder in concrete5, how can I correctly set the content-type of a single page to JSON?

McCormick
 
McCormick replied on at Permalink Reply
McCormick
Following code does the job.

<?php
defined('C5_EXECUTE') or die(_("Access Denied."));
header('content-type: application/json');
echo json_encode($json_from_custom_page_controller, JSON_PRETTY_PRINT); // echo Loader::helper('json')->encode($json_from_custom_page_controller);
exit;
?>