0

I am creating a restful api(service) using maven and jersey. My Repository attributeMasterRepository retuns the data in String format.

JSONObject attribute = new JSONObject();

    attribute.put("Product_Brand", attributeMasterRepository.getProductBrand(cluster, CouchbaseBucket.RangePlan));
    attribute.put("Product_Type", attributeMasterRepository.getProductType(cluster, CouchbaseBucket.RangePlan));

   String attributeStr = "[" + attribute.toString() + "]";      
   return attributeStr;

My above code in the Service layer returns an unexpected "\" on the string. I need to get rid of the "\".

Here is my Output:

{
 "Product_Type":
"[{\"active\":true,\"description\":\"ALL IN ONES\",\"id\":2},     
  {\"active\":true,\"description\":\"ACCESSORIES\",\"id\":1}]",
 "Product_Brand":
"[{\"active\":false,\"brand\":\"101 DALMATIANS\",\"id\":1}]"
}

Could you please let me know on how to get the "\" removed.

Thanks, IRK

Emraan
  • 143
  • 1
  • 12
  • Possible duplicate of [JSONObject.toString: how NOT to escape slashes](http://stackoverflow.com/questions/16563579/jsonobject-tostring-how-not-to-escape-slashes) – Daniel Szalay Oct 12 '16 at 08:32

1 Answers1

1

You did not state which libraries you use, but also you can just replace the \ characters:

json.replaceAll("\\\\", "");

Similar questions:

Community
  • 1
  • 1
Daniel Szalay
  • 4,041
  • 12
  • 57
  • 103