Skip to main content
varuns46785756
Level 5
Jan 12, 2016 10:55 AM UTC
Solved

Service for JCR node properties response in json

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

11 replies

edubey
Level 10
Jan 12, 2016 11:03 AM UTC

Hi,

Learn here how you can create service in AEM: https://helpx.adobe.com/experience-manager/using/first-osgi.html

Use method in your service: https://sling.apache.org/apidocs/sling6/org/apache/sling/commons/json/jcr/JsonJcrNode.html#JsonJcrNode(javax.jcr.Node)

Its will convert node properties to JSON data

Thanks

Translate
kautuk_sahni
Level 9
Jan 12, 2016 11:09 AM UTC

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

Translate
Kautuk Sahni
kautuk_sahni
Level 9
Jan 12, 2016 11:15 AM UTC

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

Translate
Kautuk Sahni
varuns46785756
Level 5
Jan 18, 2016 6:39 PM UTC

thanks

Translate
varuns46785756
Level 5
Jan 20, 2016 7:46 AM UTC

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

Translate
Jitendra_S_Toma
Level 10
Jan 20, 2016 11:33 AM UTC

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

Translate
varuns46785756
Level 5
Jan 20, 2016 6:36 PM UTC

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,

Translate