Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

CSV file to JSON with HTML

Avatar

Level 4
Level 4

Hi, 

What approach should we take to fulfill the requirement of extracting data from CSV file, displaying row data on HTML page and converting CSV data into JSON to publish it to external systems?

 

Thanks, 

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Basically you can use sling model to write your backend code to read the csv data and expose it on the HTML as we use it normally. On the same sling model you can you use sling model exporter as well using https://medium.com/@toimrank/aem-sling-model-exporter-90dc872835b9.  by default you access the json with the component path on the page using page-component.model.json and if you want to access only with pagename.model.json then you can write a sling servlet that will get bind at template level and from where you can call your sling model.

View solution in original post

4 Replies

Avatar

Community Advisor

Hi, 

If the requirement is to convert CSV data into HTML and then into JSON, one possible approach could be the following:

  1. Utilize the Content Fragment API to convert each row of CSV data into a separate Content Fragment.

  2. Assemble these Content Fragments into an HTML page, Use the Content Fragment List component 

  3.  publish it as a Content Service, which can then be consumed as JSON.

Getting Started with AEM Headless - Content Services | Adobe Experience Manager

Avatar

Community Advisor

You can write sling model exporter that can read value from csv file and can be used to write data in html as well exposed it as JSON using model.json

Avatar

Level 4
Level 4

Hi @DPrakashRaj can you please elaborate the appraoch, what exactly you want to say here

Avatar

Correct answer by
Community Advisor

Basically you can use sling model to write your backend code to read the csv data and expose it on the HTML as we use it normally. On the same sling model you can you use sling model exporter as well using https://medium.com/@toimrank/aem-sling-model-exporter-90dc872835b9.  by default you access the json with the component path on the page using page-component.model.json and if you want to access only with pagename.model.json then you can write a sling servlet that will get bind at template level and from where you can call your sling model.