Share blocks or page from Edge Delivery Services as JSON | Community
Skip to main content
Level 3
May 15, 2025
Solved

Share blocks or page from Edge Delivery Services as JSON

  • May 15, 2025
  • 4 replies
  • 664 views

How can we share a block like header or a complete page built on Edge Delivery Services [using Universal Editor] as JSON to third party/other channels.

Best answer by arunpatidar

Hi @pardeepg4829047 ,

You can't, EDS does not support page to json. however you can expose content in plain text using .plain selector.

4 replies

May 15, 2025

You can use AEM and write a sling model JSON exporter. DO not use servlet as it will have security concern over 3rd part app.

SantoshSai
Community Advisor
Community Advisor
May 15, 2025

Hi @pardeepg4829047,

I agree with @nirbhayaembee - using a Sling Model with a JSON exporter is the preferred and secure way to expose AEM content (like headers or full pages) as JSON, especially when third-party consumption is involved. I completely agree with your approach to avoid servlets, as they introduce unnecessary security and maintenance overhead.

1. Build a Sling Model for Your EDS Block (eg. Header)
  • Annotate it with @Exporter for JSON output:

@Model(adaptables = Resource.class, adapters = HeaderModel.class, resourceType = "your/components/header", defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
@Exporter(name = "jackson", extensions = "json")
2. Expose a JSON URL
3. Ensure Security
  • Do not expose servlets or unsecured APIs.

  • Use AEM permission-based access control or allow read-only access to specific endpoints via dispatcher/CDN rules.

  • Optionally apply CSRF token or signed URLs if consumed by authenticated systems.

Hope that helps!

Santosh Sai
AmitVishwakarma
Community Advisor
Community Advisor
May 16, 2025

Hi @pardeepg4829047 ,

If you’ve built a header, footer, or even a full page using Edge Delivery Services (EDS) in AEM, and you want to share that content as JSON with another system like a mobile app or external service here’s how to do it the right way.

No servlets. No unnecessary complexity. Just clean, secure, maintainable AEM code.

 

Step 1: Create a Sling Model for Your Component

Let’s say you want to expose a header block. Start by creating a Sling Model for it.

@Model( adaptables = Resource.class, resourceType = "yourproject/components/header", defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL ) @Exporter( name = "jackson", extensions = "json" ) @JsonInclude(JsonInclude.Include.NON_NULL) public class HeaderModel { @Inject private String logo; @Inject private String navLink1; @Inject private String navLink2; public String getLogo() { return logo; } public String getNavLink1() { return navLink1; } public String getNavLink2() { return navLink2; } }

This model pulls values like logo and nav links from the component’s dialog or content node.

 

Step 2: Access the JSON

Once deployed, you can hit the model like this:

https://publish.my-aem-site.com/content/mysite/us/en/_jcr_content/root/header.model.json

This will return a clean JSON object representing your component data.

You can also export an entire page this way (as long as all child components are Sling Model-enabled):

https://publish.my-aem-site.com/content/mysite/us/en/page.model.json

 

Step 3: Secure the Endpoint

Since you're exposing data over the internet, make sure it's secure.

  - Dispatcher Rules: Only allow .model.json for specific, known paths

  - Permissions: Restrict access to just what's needed. If the endpoint is public, only allow anonymous read on safe content.

  - Optional: Add token-based access or signed URLs if needed by your architecture.

Example dispatcher rule:

/0001 { /type "allow" /glob "/content/mysite/us/en/_jcr_content/root/header.model.json" }

 

Regards,
Amit

 

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
May 16, 2025

Hi @pardeepg4829047 ,

You can't, EDS does not support page to json. however you can expose content in plain text using .plain selector.

Arun Patidar
Supriya_Savre
Level 4
May 20, 2025

Hi @pardeepg4829047,

I hope the response shared above helped address your question. If it did, it would be wonderful if you could mark it as "correct reply"— this helps others in the community find helpful solutions more easily.

If you’re still facing any challenges, please feel free to continue the conversation here. We’re happy to support further.