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

Service for JCR node properties response in json

Avatar

Level 5

Hi,

I need to write a service to fetch the node properties from page component and get the JSON response .Please guide me or suggest me some reference .

 

 

 

 

thanks

1 Accepted Solution

Avatar

Correct answer by
Level 9
11 Replies

Avatar

Administrator

Hi 

Here are some of ways to get JCR values,

Link:- https://helpx.adobe.com/experience-manager/using/programmatically-accessing-cq-content-using.html

Link:- https://docs.adobe.com/docs/en/cq/5-6-1/dam/customizing_and_extendingcq5dam/query_builder.html

Link:- https://helpx.adobe.com/experience-manager/using/jqom.html

Link:-  https://helpx.adobe.com/experience-manager/using/custom-sling-servlets.html

 

Note:- Its not json response. What is the need of json response? Can you elaborate the use case ?

 

You can convert this response to JSON, by JSONObjest (Java Code ot generate JSON)

Link:- http://stackoverflow.com/questions/18983185/how-to-create-correct-jsonarray-in-java-using-jsonobject

//

import org.json.simple.JSONObject;class JsonEncodeDemo {public static void main(String[] args){JSONObject obj = new JSONObject();obj.put("name", "foo");obj.put("num", new Integer(100));obj.put("balance", new Double(1000.21));obj.put("is_vip", new Boolean(true));System.out.print(obj);}}

 Link:- http://www.tutorialspoint.com/json/json_java_example.htm

I hope this would help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Administrator

Also, to get Json as a response, you can use QueryBuilder.

Eg.

Go to:- http://localhost:4502//libs/cq/search/content/querydebug.html

Write any query...

    type=rep:User
    path=/home/users
    nodename=*
    p.limit=10

JSON QueryBuilder Link will create a link, which would return JSON as a response.

~kautuk Sahni



Kautuk Sahni

Avatar

Correct answer by
Level 9

Avatar

Level 5

thanks for all the references, Its working fine , I need to do the same thing in mobile app, shall I use the same API(code ) for mobile app also or is there any difference mobile API for this requirement.

 

 

thanks

Avatar

Level 9

Varun,

I think, there should not be an issue using this API in mobile APP. Are you having any doubt it? if yes, what is your concern and how do you want to use it?.

jitendra

Avatar

Level 5

Hi Jitendra,

Actually I am using AEM as a backend in my application( mobile app), and sending json response from AEM to WCS server, and this application will run as an APP on mobile device,my doubt is only I haven't tested it on mobile thts why I have doubt these API will work in mobile APP or not.

 

 

Regards,

Avatar

Employee Advisor

Hi,

why don't you use the default servlets?

kind regards,
Jörg