Expand my Community achievements bar.

SOLVED

Handling \\n Characters in AEM Content Fragments

Avatar

Level 4

Hi Team

When inputting a newline character (\n) in any text field of an AEM content fragment, the JSON output shows \\n instead of \n. This leads to inconsistencies, as the UI displays the newline correctly, but the JSON response doesn't reflect the intended formatting

How to address this any advise.

Thanks in advance.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi @Prashardan ,

 

Use multi-value rich text property for updating the special characters in the CF field. 

Just enter the content in new line in CF field. In the JSON it appends /n on it's own when rich text property used like below -

 

PRATHYUSHA_VP_1-1738062839015.png

 

 

PRATHYUSHA_VP_0-1738062784199.png

 

Hope this helps

 

Thanks

 

 

View solution in original post

2 Replies

Avatar

Correct answer by
Level 7

Hi @Prashardan ,

 

Use multi-value rich text property for updating the special characters in the CF field. 

Just enter the content in new line in CF field. In the JSON it appends /n on it's own when rich text property used like below -

 

PRATHYUSHA_VP_1-1738062839015.png

 

 

PRATHYUSHA_VP_0-1738062784199.png

 

Hope this helps

 

Thanks

 

 

Avatar

Level 7

To handle newline characters (\n) properly in AEM Content Fragments, you can use a multi-value rich text property. When you enter content with line breaks in the Content Fragment field, AEM will automatically encode it with \n for line breaks.
Solution:

1. Use Multi-value Rich Text Property: This allows AEM to handle newline characters properly when the content is entered in the field.

2. Behavior: When using this property, you can enter the content with new lines, and AEM will ensure that \n appears in the JSON output instead of \\n.