Regarding the unexpected JSON output issue you're encountering with your DXA implementation behind CloudFront and a load balancer, it's important to consider how the DXA framework handles page requests and responses.
By default, DXA is designed to load the appropriate Page Model based on the requested page URL, map it to the corresponding View Model, and then render it as HTML for web display. However, DXA also supports the option to return JSON format if explicitly requested via the URL query string, typically by appending ?format=json to the page URL. This functionality is useful for scenarios where applications need to consume page content in JSON format rather than as rendered HTML.
In your case, where pages are unexpectedly rendered in JSON format, it's possible that something in your environment is altering the request headers, specifically the content type and accept type, which might prompt the DXA framework to return JSON instead of HTML.
To troubleshoot this issue effectively, I recommend the following steps:
Examine Request Headers: When encountering the JSON output, inspect
the request headers to see if the content type and accept type
headers are being modified. This information can provide insights
into what might be triggering the unexpected behavior.
Review Customizations and Configurations: Take a closer look at any
custom middleware, CDN settings, or other environment configurations
that could potentially impact the handling of requests and
formatting of responses. Pay particular attention to any components
that interact with request headers or manipulate response content.
Check for Additional Query Parameters: Verify if any additional
query parameters are being appended to the page URLs, potentially
triggering the JSON response format. This can help identify any
unintentional modifications to the request that might be influencing
the DXA framework's behavior.
By thoroughly investigating these aspects, you should be able to
pinpoint the root cause of the issue and implement the necessary
adjustments or fixes to ensure consistent rendering of pages in the
expected HTML format.
I hope it helps to troubleshoot your issue.