Expand my Community achievements bar.

SOLVED

Need suggestion on storing data containing special characters

Avatar

Community Advisor

Dear community members,

I'm trying to create JCR nodes based on the data returned by http get. Some of the data contains special characters.

 

..
..
"details": [
{
"label": "Présentation de l’entreprise:",
"value": "<p style=\"margin: 0px;\">Chez , nous donnons aux gens la possibilit&eacute; d'interagir naturellement avec leurs divers appareils connect&eacute;.</p>"
},
{
"more-details": "Sommaire du poste: ",
"value": "<p style=\"margin: 0in; margin-bottom: .0001pt;\"><span style=\"font-family: arial, helvetica, sans-serif; font-size: 10pt;\">"
},
..
..

 

I cannot directly save the data, can someone please suggest a way I can save this information? I need to display the information as well.

 

Just to give another insight, I cannot create i18 key-value pair for this data(yeah )

 

Thanks,

Bilal.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @bilal_ahmad 

why don't you create a node and save the whole API response as nope property?[Like a node "response" in JCR repository and a property apiResponse as key and json as value]

 

You can create the node and property in AEM programmatically and there are various ways of doing that like using sling or node API.

 

Go through below links to refer the code 

Programatically create node

create content node

 

Regards,

Arpit

 

View solution in original post

6 Replies

Avatar

Correct answer by
Community Advisor

Hi @bilal_ahmad 

why don't you create a node and save the whole API response as nope property?[Like a node "response" in JCR repository and a property apiResponse as key and json as value]

 

You can create the node and property in AEM programmatically and there are various ways of doing that like using sling or node API.

 

Go through below links to refer the code 

Programatically create node

create content node

 

Regards,

Arpit

 

Avatar

Community Advisor

Thanks ton, @ArpitVarshney for your sharing valuable thoughts, it was indeed thoughtful. If I save the whole JSON response as node, I have two things to accomplish:
1. Use the node data(saved json) to build a UI(show data on my page).

2. Search in the JSON(which i'm hesitant to do )

Do you know any way I can incorporate the architecture you shared, to save the incoming response and the things I want to achieve(above two points)?
Many Thanks,

Bilal.

Avatar

Community Advisor

Hi @bilal_ahmad 

 

I don't think there will be any challenging issue creating UI based on JSON. I've done it various times in the past.

There can be two approaches:

  • create a component where on page load you call sling model and get the required field from JSON after putting your business logic and send it back to HTL for creating the UI.
  • Another approach can be that you can create an ajax based component where you can call your AEM servlet from JS which returns the required field from JSON after putting your business logic and then create UI in Javascript by forming HTML. This approach would be useful if you are implementing search functionality based on JSON.

I'm not sure about what do you mean by the search. Do you want to implement search functionality based on this JSON?

Go through these links if this helps:

https://stackoverflow.com/questions/10679580/javascript-search-inside-a-json-object

https://www.js-tutorials.com/jquery-tutorials/live-search-json-objects-data-using-jquery/

 

Regards,

Arpit

Avatar

Community Advisor

Thank you @ArpitVarshney, really appreciate your efforts on this.

The real issue seemed to be the encoding(yeah, idk why that happened because i'm using AEM6.4.4 and I don't understand why it didn't let me save the data).

 

The reason I'm saving every incoming objects(key-value pair) in node property is, to have a readable/easy structure. Still, I will try your solution as well, for that will not make me write a lot of code

 

Many Thanks,

Bilal.

Avatar

Community Advisor

This can be done easily.

Create node based on the response, valid node name can be set using https://helpx.adobe.com/experience-manager/6-2/sites/developing/using/reference-materials/javadoc/co...

data can be mapped as child nodes and properties.

Encode property values before saving.

 

If you are planning to map this data for a component then you can divide these data into small components.

 



Arun Patidar