Vinaya Maheshwari
Vinaya Maheshwari

Reputation: 575

How to remove double quotes from Json string data using Jquery

My jQuery script as below:

jQuery.ajax({
    type:"GET",
    url:url, 
    data:'action=getStatus', 
}).done(function(response){ 
    var data = jQuery.parseJSON(response);

    var test = data['visitor_chart'];
})  

My jQuery.ajax return response in below form:

"{"visitor_chart":"{y: 3, label: \"2015-07-21\"}, {y: 1, label: \"2015-07-29\"}, {y: 1, label: \"2015-07-30\"}, {y: 1, label: \"2015-08-01\"}","visitor_count":6,"enquiry_count":1}"

After parseJSON I got data['visitor_chart'] in below form:

"{y: 3, label: "2015-07-21"},{y: 1, label: "2015-07-29"},{y: 1, label: "2015-07-30"},{y: 1, label: "2015-08-01"}"

but I want to strip first and last quote from this string.

How to do that?

Upvotes: 3

Views: 9575

Answers (2)

Ahmed Bermawy
Ahmed Bermawy

Reputation: 2530

you can use also replaceAll

var test = data['visitor_chart'];

console.log(test.replaceAll('"', ''));

Upvotes: 0

dpanshu
dpanshu

Reputation: 463

to replace first quote :

str=str.replace(/^"/, "");

to replace last quote :

str=str.replace(/"$/, "");

Verified here. It's working

Upvotes: 2

Related Questions