Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Remove backslash from Json Object

Avatar

Community Advisor

[Thread Edited By Adobe]

/*Don’t forget to meet and greet your fellow peers virtually by telling them about yourself here

Go ahead and to it now: https://adobe.ly/3eDnB4v */

 

Actual Question:

Hi,

I've created a json object which I'm adding value like json.put(key, value).

While I add value which already contains " " then it add backslash before double quotes.

How can I remove it?

Thanks,

Himanshu

desktop_exl_promo_600x100_gdrp.png

1 Accepted Solution

Avatar

Correct answer by
Level 10
4 Replies

Avatar

Level 10

Java tried to escape your string as " " is part of your string not actual quotes which are used in start and end

so that when you output string u get same string else you wont

which json library u r using?

Avatar

Community Advisor
{ "identity": { "name": "Test", "moduleType": "rwdHtmlPromoModule" }, "htmlInfo": { "htmlBlock": "<div class=\"promo-bleed\"> <div class=\"max-width-1200\">   <a href=\"http://localhost:4502/content/dam/dtv/teamsite/rwd/ent/movies/201602/Oscar_Ballot_2016.pdf\" target=\"_blank\">     <img src=\"/content/dam/dtv/teamsite/rwd/ent/movies/201602/sm_bnr__OSCAR_Ballot_Banner.jpg\" class=\"promo-image show-sm\">     <img src=\"/content/dam/dtv/teamsite/rwd/ent/movies/201602/md_bnr__OSCAR_Ballot_Banner.jpg\" class=\"promo-image show-md\">     <img src=\"/content/dam/dtv/teamsite/rwd/ent/movies/201602/lg_bnr__OSCAR_Ballot_Banner.jpg\" class=\"promo-image show-lg show-xl\">   </a> </div></div> </div></div>" } }

 

This is my json data. All I want is to remove backslash from here bcz it's breaking the anchor link, finally.

JSON API : org.apache.sling.commons.json.JSONObject

Avatar

Level 10

Can you share a background of wht are u trying to do 

Are u taking this data from servlet and putting it in its place use JS?

Avatar

Correct answer by
Level 10