how do I output am EE html template as a json file so it validates? Error:Invalid media type, expecting application/json.

I have tried enabling php to my template and adding the following code after all my data is parsed

But I get this in the output: {!-- ra:000000006fa9a5900000000053584a0b --}[ and the file will not validate.

BUT if I copy and paste the outputted data into a json validator it validates. My only issue is the media type.


As mentioned in another answer, you could go with the HTTP header plugin, but the same developer (Rob Sanchez) has also made a JSON plugin that allows for many more JSON specific settings.

If you are looking to install this to EE3, you'll need to make a couple of changes to the plugin files as the plugin itself was made for EE2. However the changes take less than 5 minutes to do. Check the GitHub issues tab for this info.


Install "HTTP Header" Plugin to set the EE html template as a json.

{exp:http_header content_type="application/json"}

Not the answer you're looking for? Browse other questions tagged or ask your own question.