Remove backslash from Json Object | Community
Skip to main content
Himanshu_Singhal
Community Advisor
Community Advisor
February 25, 2016
Solved

Remove backslash from Json Object

  • February 25, 2016
  • 4 replies
  • 72397 views

[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

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

Here is a good Stackoverflow thread that can help: 

http://stackoverflow.com/questions/21036626/remove-backslashes-from-json-data-in-javascript

4 replies

edubey
Level 10
February 25, 2016

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?

Himanshu_Singhal
Community Advisor
Community Advisor
February 25, 2016
{ "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

edubey
Level 10
February 25, 2016

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?

smacdonald2008
smacdonald2008Accepted solution
Level 10
February 26, 2016