Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Read the Node data in json format

Avatar

Level 2

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.



Arun Patidar

View solution in original post

2 Replies

Avatar

Level 10

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.

Avatar

Correct answer by
Community Advisor

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.



Arun Patidar