write to JCR from JSON data | Community
Skip to main content
New Participant
January 17, 2017
Solved

write to JCR from JSON data

  • January 17, 2017
  • 4 replies
  • 6564 views

I'm receiving JSON data from a service call programatically.

Now, I want to save/upload the JSON data to the JCR as a .txt file programatically. What is the best approach to achieve this ?

Appreciate your help. Thanks!

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 kautuk_sahni

+1 with Scott solution.

Adding few extra reference articles here:

Link:- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__7ngr-hi_all_wanted.html

// Create JCR nodes from json string

 

Link:- http://asserttrue.blogspot.in/2012/05/importing-json-data-into-java-content.html#

//Importing JSON data into a Java Content Repository

I hope this would help you.

~kautuk

4 replies

smacdonald2008
New Participant
January 18, 2017

Check the links that Kautuk added. In the tools we have coded for AEM - we have always used the JCR/JCR SQL2 to do the job. 

anireddyAuthor
New Participant
January 18, 2017

smacdonald2008 wrote...

Write a custom AEM service and then use JCR API to update the nodes. 

Parse the values from JSON and then use API to update the nodes in the JCR -- for example: 

//Store content from the client JSP in the JCR
   Node custNode = customerRoot.addNode("customer"+firstName+lastName+custId,"nt:unstructured"); 
               
  //make sure name of node is unique
  custNode.setProperty("id", custId); 
  custNode.setProperty("firstName", firstName); 
  custNode.setProperty("lastName", lastName); 

 

See: https://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content1.html

This will point you in the correct direction. 

 

 

Thank Scott for the reply. I'm dealing with huge data so I think parsing the json and adding it in the repo takes down the performance. I was wondering if there is a way to have my response (from the service call) directly save in the JCR !!

kautuk_sahni
kautuk_sahniAccepted solution
Employee
January 18, 2017

+1 with Scott solution.

Adding few extra reference articles here:

Link:- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__7ngr-hi_all_wanted.html

// Create JCR nodes from json string

 

Link:- http://asserttrue.blogspot.in/2012/05/importing-json-data-into-java-content.html#

//Importing JSON data into a Java Content Repository

I hope this would help you.

~kautuk

Kautuk Sahni
smacdonald2008
New Participant
January 17, 2017

Write a custom AEM service and then use JCR API to update the nodes. 

Parse the values from JSON and then use API to update the nodes in the JCR -- for example: 

//Store content from the client JSP in the JCR
   Node custNode = customerRoot.addNode("customer"+firstName+lastName+custId,"nt:unstructured"); 
               
  //make sure name of node is unique
  custNode.setProperty("id", custId); 
  custNode.setProperty("firstName", firstName); 
  custNode.setProperty("lastName", lastName); 

 

See: https://helpx.adobe.com/experience-manager/using/persisting-cq-data-java-content1.html

This will point you in the correct direction.