Read the Node data in json format

Avatar

Avatar

shashanks526115

Avatar

shashanks526115

shashanks526115

24-06-2019

Hello,

        I am shashank singh. I am trying to read the node properties in json formate but i am getting the error message.. so is there any way to read the node property from dam path in json format.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

999

Correct Answer

829
Arun_Patidar
MVP

24-06-2019

Hi,

You can read it using google gson API.

e.g. read node properties as ValueMap and convert this object into json using gson.toJson(valueMapObj)

Example, if you are doing this in servlet

Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();

ValueMap valueMap = req.getResourceResolver().getResource("/content/we-retail/jcr:content").getValueMap();

String jsonStr = gson.toJson(valueMapObj)

Note: for jcr:data or other binary type property can't be exposed in JSON, so remove from valueMap before converting to json.

Answers (1)

Answers (1)

Avatar

Avatar

Gaurav-Behl

MVP

Total Posts

1.1K

Likes

226

Correct Answer

281

Avatar

Gaurav-Behl

MVP

Total Posts

1.1K

Likes

226

Correct Answer

281
Gaurav-Behl
MVP

24-06-2019

Did you get a chance to go through Assets HTTP API  or Content Fragments Support in AEM Assets HTTP API since your requirements use DAM path?

You could even use custom exporter based on the complexity of your use case.