Stringified Json Has Unwanted Double Quotes

Stringified JSON has unwanted double quotes

Don't stringify things that are not objects. Just use them.

$.get("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22canberra%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys",function(data) {  $(document.body).append("Count: " + data.query.count);   $("#heading").append(data.query.results.channel.title);}, "json");
<!DOCTYPE html><html lang="en">  <head>    <title>Yahoo Weather for Canberra</title>    <meta charset="utf-8">    <script src="https://code.jquery.com/jquery-3.3.1.js"></script>  </head>  <body>    <h1 id="heading"></h1>  </body></html>

Remove double quotes from JSON String

Try to replace "[ with [ and ]" with ]

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

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

How to remove unwanted double quotes when converting CSV to JSON in angular

In the end, I did it this way:

for (var m=0; m<array.length; m++){
array[m].id = array[m].id.substring(1, array[m].id.length-1);
array[m].level = array[m].level.substring(1, array[m].level.length-1);
array[m].date = array[m].date.substring(1, array[m].date.length-1);
}

May not be the best way but it works for me in the current context. Am still looking for ways to improve on this. Thank you!

Dump to JSON adds additional double quotes and escaping of quotes

You are double encoding your JSON strings. data is already a JSON string, and doesn't need to be encoded again:

>>> import json
>>> not_encoded = {"created_at":"Fri Aug 08 11:04:40 +0000 2014"}
>>> encoded_data = json.dumps(not_encoded)
>>> print encoded_data
{"created_at": "Fri Aug 08 11:04:40 +0000 2014"}
>>> double_encode = json.dumps(encoded_data)
>>> print double_encode
"{\"created_at\": \"Fri Aug 08 11:04:40 +0000 2014\"}"

Just write these directly to your file:

with open('data{}.txt'.format(self.timestamp), 'a') as f:
f.write(data + '\n')

Remove quote from the JSONArray output

1. .replaceAll()

testValue.toString().replaceAll("\"", "");

This method replace all the double quotes which are present in your name not the first and the last.

Example : "Abcd" becomes Abcd but if the name is "Ab"cd" it should be Ab"cd according to your requirement but it becomes Abcd. Mean to say that all the double quote replaced.

2. substring()

If you want to use the substring method approach then use the following syntax to remove the first and the last double quotes from your string:

testValue.toString().subString(1,testValue.toString().length()-1);

1 - indicates the first character of the string

testValue.toString().length()-1 : indicates the last character of the string.

For your case .substring() method is more better than the .replaceAll(), if .getString() not working.

3. .ValueOf() OR .getString()

Don't know In your case why it is not working ? (may be because the string itself containing the quotes) other wise the best way is to Convert the JSONValue to the String as String.ValueOf(testValue);

OR

childJSONObject.getString("name");

Otherwise give preference as : 3 > 2 > 1

How to remove unwanted characters (brackets, quotes, and commas) from a JSON string?

You already have your JSON data in a string, so you need to parse it into a JavaScript object (an array in your case):

JSON.parse(jsonString)

This will give you a data structure that you can iterate over, to extract each item in a clean way.

Here is a demo: