JSON inside string | Adobe Higher Education
Skip to main content
Level 5
October 30, 2020
Beantwortet

JSON inside string

  • October 30, 2020
  • 3 Antworten
  • 2110 Ansichten

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>

 

 

 

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von SureshDhulipudi

Did you try with encoding

 

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

3 Antworten

Anudeep_Garnepudi
Community Advisor
Community Advisor
October 30, 2020

Hi @v1101 

Replace all double quotes with single quotes.

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

AG

AG
kautuk_sahni
Community Manager
Community Manager
November 3, 2020
Thank you for sharing this answer.
Kautuk Sahni
Manjunath_K
Level 7
October 30, 2020

Hi @v1101 

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>

 

 

Access same data attribute values in front end:

 

 

 

Hope this helps!

SureshDhulipudi
Community Advisor
Community Advisor
October 31, 2020

Did you try with encoding

 

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