Service for JCR node properties response in json | Adobe Higher Education
Skip to main content
varuns46785756
Level 5
January 12, 2016
Beantwortet

Service for JCR node properties response in json

  • January 12, 2016
  • 11 Antworten
  • 6993 Ansichten

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

Dieses Thema wurde für Antworten geschlossen.

11 Antworten

edubey
Level 10
January 12, 2016

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

kautuk_sahni
Community Manager
Community Manager
January 12, 2016

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
kautuk_sahni
Community Manager
Community Manager
January 12, 2016

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
varuns46785756
Level 5
January 18, 2016

thanks

varuns46785756
Level 5
January 20, 2016

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

Jitendra_S_Toma
Level 10
January 20, 2016

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

varuns46785756
Level 5
January 20, 2016

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,