Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to Export Conent Fragment data as a JSON to third party system using an endpoint with servlet in AEM

Avatar

Level 5

Hi Everyone,

 

I want to export my conent fragment data in JSON format using specfic end point with servlet, I want the ouput of the data like below attached screenshot, Kindly Help me if you have any ideas for this issue.

output.jpeg

 

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@Nandheswara Please check this below example for the servlet to return JSON.You need to write the logic to get the content fragment into the json

https://gist.github.com/nateyolles/d4ca683078efd60aa8ac

 

View solution in original post

4 Replies

Avatar

Community Advisor

hello @Nandheswara 

 

There are multiple options to export Content Fragments as json

 

Option-1:

OOTB Content Services would allow to access Content Fragment data by appending .model.json to the CF. Reference: https://experienceleague.adobe.com/docs/experience-manager-65/developing/components/json-exporter.ht...

 

It essentially works with Content Fragment component. Example: Add CF to a page via Content Fragment component. Then access its data as http://localhost:4502/content/experience-fragments/wknd/language-masters/en/contributors/stacey-rosw... 

 

 

Option-2: You should try exploring GraphQL to get Json output from Content Fragments. They are pretty powerful.

https://experienceleague.adobe.com/docs/experience-manager-learn/getting-started-with-aem-headless/g... 


Aanchal Sikka

Avatar

Level 5

I want to export data using servlet so if there any blog means give please

Avatar

Correct answer by
Community Advisor

@Nandheswara Please check this below example for the servlet to return JSON.You need to write the logic to get the content fragment into the json

https://gist.github.com/nateyolles/d4ca683078efd60aa8ac

 

Avatar

Community Advisor

The preferred way to expose the Content Fragment data is through GraphQL, some of the advantages are:

 

  1. Enhance cache: the GraphQL endpoints can be stored and cached, improving the performance overall.
  2. Efficient Data Fetching: GraphQL allows clients to specify the exact data they need, eliminating over-fetching and under-fetching issues commonly found in traditional RESTful APIs.

  3. Flexible and Customizable Queries: With GraphQL, clients have the flexibility to define their own queries to fetch the required data. They can specify the fields, relationships, and fragments they need, enabling them to fetch multiple content fragments in a single request. 

  4. Strong Typing and Schema Validation: GraphQL has a strongly typed schema, which acts as a contract between the client and server. This schema allows clients to understand the available data and its structure. Additionally, GraphQL provides schema validation, enabling early detection of errors and providing a clear contract for API consumers.

  5. Reduced Overhead for Backend Development: Developers can add or modify fields within the schema without impacting existing clients, making it easier to evolve the API over time.

  6. Frontend Agnostic: GraphQL decouples the backend from the frontend, allowing clients to choose their preferred programming language or framework. 

Why would be the reason to avoid GraphQL and use a servlet instead?



Esteban Bustamante