Create node By Json Data | Community
Skip to main content
varuns46785756
Level 5
February 2, 2017
Solved

Create node By Json Data

  • February 2, 2017
  • 2 replies
  • 2989 views

Hi,

I need to write a servlet to hit the third party URL(its a open source url) and this URL returning data in json format.I need to store these data in node.Please suggest

 

 

Regards,

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by kalyan_venkat
Inside servlet  use HTTPClient (from apache commons) api to hit 3rd party url and get the data. If you response is in JSON format use JSONObject or JSONArray objects (from sling commons) and inject the response to the constructors of those objects. From those json objects you get the values by passing keys. Now to create new nodes use Node api (from javax.jcr) and set appropriate properties to the node and save the session by using session.save() method. PS: Your nodes will be created only after execution of session.save() method

2 replies

kalyan_venkatAccepted solution
Level 3
February 2, 2017
Inside servlet  use HTTPClient (from apache commons) api to hit 3rd party url and get the data. If you response is in JSON format use JSONObject or JSONArray objects (from sling commons) and inject the response to the constructors of those objects. From those json objects you get the values by passing keys. Now to create new nodes use Node api (from javax.jcr) and set appropriate properties to the node and save the session by using session.save() method. PS: Your nodes will be created only after execution of session.save() method
smacdonald2008
Level 10
February 2, 2017

See this AEM article that shows you how to use the JCR API to save data in the JCR -- 

http://scottsdigitalcommunity.blogspot.ca/2014/12/querying-adobe-experience-manager-6.html

In your servlet - after you get back the JSON data, create app logic to store the data in the JCR.