CSV file to JSON with HTML | Community
Skip to main content
Level 3
March 23, 2023
Solved

CSV file to JSON with HTML

  • March 23, 2023
  • 2 replies
  • 1954 views

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, 

 

 

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 DPrakashRaj

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.

2 replies

Nitin_laad
Community Advisor
Community Advisor
March 23, 2023

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

DPrakashRaj
Community Advisor
Community Advisor
March 25, 2023

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

nj2Author
Level 3
March 27, 2023

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

DPrakashRaj
Community Advisor
DPrakashRajCommunity AdvisorAccepted solution
Community Advisor
March 27, 2023

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.