Hi @Nandheswara ,
Did you tried with one of the OOTB functionality? eg. http://localhost:4502/editor.html/content/we-retail/language-masters/en/men.model.tidy.json
Reference: Obtaining Page Information in JSON Format
If that doesn't suits your requirement , I would suggest to use Sling Model Exporter rather than servlet.
Exporting page content as JSON using Sling Model Exporter you can get below advantages
- No need to write servlet to export data as JSON format
- You can use same code which is written using Sling Model to render content and to export as JSON format
Sling model exporter is very useful when you want to publish your data to third party system’s or consuming within the site using ajax request if you have sling models and wants to serialize them, by providing simple @Exporter annotations to the existing sling models you can convert your model to CaaS based URL.
Here is the github code: SampleSlingModelExporter.Java from Adobe-Consulting-Services
Reference: No Servlets Required: Exporting Data with Sling Models
However, If you still want's to achieve it through Servlet - @arunpatidar has done POC on it, please refer: https://github.com/arunpatidar02/aem63app-repo/tree/master/java/page/json
Hope that helps!
Regards,
Santosh