Converting AEM/Sling Resources to JSON

Adobe Experience Manager | AEM/CQ | Apache Sling

Converting AEM/Sling Resources to JSON

You can easily convert an AEM Page, Sling Resource, or JCR Node to JSON using the class. This simply but useful utility allows you to dump a Node into a JSONObject. It also allows you to dump the Node into a JSON string into a PrintWriter for use in servlets for example.

The constructor accepts a Set of Strings representing JCR properties to exclude from the JSON output. You may want to ignore the standard cq:*, sling:* and jcr:* properties while allowing only your custom properties to populate the JSON.

The overloaded dump methods allow you to pass in the recursion level similar to how you would use a selector when making AJAX calls to the Default Get Servlet. Just as you can cURL /content/geometrixx/en.json, /content/geometrixx/en.1.json and /content/geometrixx/en.-1.json, you can pass in a positive integer for the recursion level as well as -1 for infinite recursion.

Likewise, just as you can cURL /content/geometrixx/en.tidy.json, you can specify whether you want the JSON output nicely formatted or not.

The following examples demonstrate the JsonItemWriter utilizing a PrintWriter in a servlet and a JSONObject in a standard Java class.


sudhanshu Sharma | June 14, 2017 at 06:39 AM | Reply

Very nice explanation and great piece of knowledge. Thanks alot.

Sceptic | April 24, 2019 at 01:14 PM | Reply

And `ResourceResolver` is a parameter because...?

Nikhil Kumar | October 04, 2019 at 12:13 PM | Reply

Following is the solution for getting data from DAM and writing the Data.

AvereottTecemog | December 14, 2019 at 11:19 PM | Reply

fuse hemp oil <a href="">benefits of hemp oil for humans</a> cannabis cream

AvereottTecemog | December 17, 2019 at 11:54 AM | Reply

cbd cream amazon <a href="">cbd pure hemp oil</a> cannabis oil for seizures

AvereottTecemog | December 17, 2019 at 06:31 PM | Reply

cbd daily intensive cream <a href="">hemp oil cbd</a> 1000 mg cbd gummies

AvereottTecemog | December 17, 2019 at 08:31 PM | Reply

pch slots tournament <a href="">free casino</a> pala casino online

AvereottTecemog | December 17, 2019 at 08:58 PM | Reply

play free slot machines with bonus spins <a href="">online casino</a> vegas casino games slots free

AvereottTecemog | December 17, 2019 at 10:25 PM | Reply

online casino reviews <a href="">no deposit casino</a> online casinos for us players

AvereottTecemog | December 18, 2019 at 06:19 AM | Reply

casino games slots free <a href="">casino play</a> virgin online casino

AvereottTecemog | December 18, 2019 at 09:02 PM | Reply

absolutely free casino slots games <a href="">casino bonus codes</a> liberty slots

Swati | December 30, 2019 at 11:10 AM | Reply

Is there any option to ignore all jcr and cq properties while taking the dump of a node instead of manually adding each and every jcr property? I could not find wildcard support in JSONItemWriter for "jcr:*", "cq:*" Thanks

Leave a Comment