.model.json not showing component JSON at page level but only at specific component node level | Community
Skip to main content
Himanshu_Singhal
Community Advisor
Community Advisor
May 12, 2020
Solved

.model.json not showing component JSON at page level but only at specific component node level

  • May 12, 2020
  • 2 replies
  • 8440 views

Hi,

 

I've written JSON exporter with Sling model to expose it as JSON. When I try to drag the component on page and then check it with <page url>.model.json - it doesn't show the component JSON. But, when I get to specific node path e.g. <page-node-path>.model.json then it returns the component JSON. 
Any idea why it's happening like that?

 

Best regards,
Himanshu Singhal

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by BrianKasingli

@himanshu_singhal,

Apache Sling Models currently includes a single exporter, using the Jackson framework, which is capable of serializing models as JSON. Adobe's new core components are built with Sling Models, meaning that if you can easily build a headless AEM solution only using the core components. If you are using Adobe's core page component, layout container, responsive grid component in editable templates, you can replace ".html" with ".model.json", and you will get a JSON representation of the page structure (resourceType & all used components); assuming that you're Apache Dispatcher module rules allow you to access .model.json. e.g: https://example.com/home.model.json

Then there's no magic happening with the Jackson Exporter; all getter properties of your Sling Models class will exposed, and serialized to JSON. This means that if you run some kind of logic in your @PostConstruct method, then set the property, the computed value will be exposed in your JSON.

2 replies

BrianKasingli
Community Advisor and Adobe Champion
BrianKasingliCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
May 12, 2020

@himanshu_singhal,

Apache Sling Models currently includes a single exporter, using the Jackson framework, which is capable of serializing models as JSON. Adobe's new core components are built with Sling Models, meaning that if you can easily build a headless AEM solution only using the core components. If you are using Adobe's core page component, layout container, responsive grid component in editable templates, you can replace ".html" with ".model.json", and you will get a JSON representation of the page structure (resourceType & all used components); assuming that you're Apache Dispatcher module rules allow you to access .model.json. e.g: https://example.com/home.model.json

Then there's no magic happening with the Jackson Exporter; all getter properties of your Sling Models class will exposed, and serialized to JSON. This means that if you run some kind of logic in your @PostConstruct method, then set the property, the computed value will be exposed in your JSON.

bsr060893
Level 3
August 19, 2020
Hi,
Shashi_Mulugu
Community Advisor
Community Advisor
May 12, 2020

Sling Model Exporter works based on resource type. As per your post, you have written Sling Model exporter for Component, so .model.json works on component only. If you need the Json at page level, develop a sling model with exporter annotations for Page Resource Type