Expand my Community achievements bar.

SOLVED

Alternative library to jsonWriter to convert page to Json

Avatar

Level 3

Hi all,

 

I am implementing AEM site search functionality using elastic search. My requirement is to extract the page content as json and push it to Elastic search for indexing. I will have to do this on author on an event . 

I have implemented this using com.day.cq.commons.TidyJsonItemWriter and jsonWriter.dump(node, out, 10) which gives me desired output . My concern is, this method throws JSONException which is of class org.apache.sling.commons.json.JSONException; and its a deprecated hence i don't want to use it . Could some one suggest what would be the best way to achieve json dump for my page content including all the components in a page.

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
6 Replies

Avatar

Employee Advisor

Although Sling Commons JSON is deprecated, it's not going to be removed in the AEM product anytime soon (at least until a replacement is provided).

If it works right now for you, I would stick with it.

Avatar

Level 3

Thanks for the response . I might just stick with Json writer for now in that case

Avatar

Level 3

Hi , 

 

The solution in that thread can not be applied in my case as I want to extract the json dump of the content for already built components and pages  so that i can index the content in elastic cache. Thank you so much for the response

Avatar

Correct answer by
Community Advisor

Hi,

You can use gson from google.

Example https://aemlab.blogspot.com/2019/07/get-json-response-of-aem-page.html



Arun Patidar

Avatar

Level 3

Thanks for the response . This looks good as alternative to get the Json dump .