Apache Sling provides a Jackson JSON exporter to satisfy common cases of exporting Sling Models as JSON objects for consumption by SPAs.
import com.fasterxml.jackson
You can utilise the AEM WCM Core V2 Page Component for page creation, where when you include the selector of "model" and extension of "json", you will get a JSON representation of the page. There's no magic happening with the WCM Core V2 Page Component. It simply returns a JSON representation of all the components that exist on the page, formatted. Each component, however, must have a 1 to 1 relationship with a Sling Model, and the sling model must be programmatically configured with the Jackson JSON exporter.
AEM WCM Core V2 Components are all implemented with Sling Models and Jackson Exporters, so if you would like to test this feature, you can simply create a new page using the WCM Core V2 Page Component, next you can start constructing the page with the WCM Core V2 Components. Next, visit the webpage via /content/my-site/page.model.json, and you will get a JSON representation of the entire page, ready for consumption by SPAs.
A good article here is: