issue with json data for composite field in content fragment | Community
Skip to main content
May 13, 2021
Question

issue with json data for composite field in content fragment

  • May 13, 2021
  • 1 reply
  • 624 views

Implemented composite multifield.

http://experience-aem.blogspot.com/2018/10/aem-6420-assets-content-fragments-coral-3-composite-multifield.html 

 

Need the array to be json array than string array.

 

issue json coming as String Array

0 "{\"linkName\":\"test\",\"linkUrl\":\"test\"}"
1 "{\"linkName\":\"test\",\"linkUrl\":\"test\"}"

 

expected as json array as below.

0 {\"linkName\":\"test\",\"linkUrl\":\"test\"}
1 {\"linkName\":\"test\",\"linkUrl\":\"test\"}

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Asutosh_Jena_
Community Advisor
Community Advisor
May 14, 2021

Hi @sauravk75866207 

 

The String Array that you have mentioned is a valif JSON whereas the expected JSON array you mentioned is not a valid JSON.

 

do you mean by:

[{\"linkName\":\"test\",\"linkUrl\":\"test\"}, {\"linkName\":\"test\",\"linkUrl\":\"test\"}]

to 

"[{\"linkName\":\"test\",\"linkUrl\":\"test\"}, {\"linkName\":\"test\",\"linkUrl\":\"test\"}]"

 

If that's the case you can use the Gson API.

 

String x = input;
Gson gson = new Gson();
String toJson = gson.toJson(x);