JSON inside string

Avatar

Avatar

viki1101

Avatar

viki1101

viki1101

30-10-2020

Hello Community - We run into an issue with storing the JSON inside a string property. Basically we have a property with the type String, in that property we are having a paragraph and hyperlinks in it. As part of the hyperlink, we need to store some JSON string. We tried using escape characters for JSON key and value but it is not saving in JCR. Could someone let me know the way to handle this use case. As we don't want to create a separate String / String [] property for storing the JSON.

 

String:

Test String <a data-test-attr="{\"Test\":\"Data\"}" href="https://www.google.com" >Test Page</a>

 

viki1101_3-1604076793168.png

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

sureshd71454102

Avatar

sureshd71454102

sureshd71454102

31-10-2020

Did you try with encoding

 

<a data-test-attr="{%22Test%22:%22Data%22}" href="https://www.google.com" >Test Page</a>AEM-String-URL.png

Answers (2)

Answers (2)

Avatar

Avatar

Manjunath_K

Avatar

Manjunath_K

Manjunath_K

30-10-2020

Hi @viki1101 

Try to add data attribute value within single quote as mentioned below, then it will save value as expected.

 

Test String <a data-test-attr='{"Test":"Data"}' href="https://www.google.com" >Test Page</a>

 

json.PNG

 

Access same data attribute values in front end:

json2.PNG

 

 

json1.PNG

 

Hope this helps!

Avatar

Avatar

Anudeep_Garnepudi

Avatar

Anudeep_Garnepudi

Anudeep_Garnepudi

30-10-2020

Hi @viki1101 

Replace all double quotes with single quotes.

<a data-test-attr='{"Test":"Data"}' href='https://www.google.com'>Test Page</a>

AG