Expand my Community achievements bar.

SOLVED

write to JCR from JSON data

Avatar

Level 2

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!

1 Accepted Solution

Avatar

Correct answer by
Administrator

+1 with Scott solution.

Adding few extra reference articles here:

Link:- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

// 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

View solution in original post

4 Replies

Avatar

Level 10

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. 

Avatar

Correct answer by
Administrator

+1 with Scott solution.

Adding few extra reference articles here:

Link:- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...

// 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

Avatar

Level 2

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 !!

Avatar

Level 10

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.