0
var str = "\\\"";
var jsondata = JSON.stringify(response.data).replace(str, "");

This code dont work. sample JSON:

[{ ID: 1, text: \"Meat\" }
5
  • 4
    That is not valid JSON. You should fix the source, not the symptoms. Commented Apr 3, 2018 at 9:24
  • Please read How to create a Minimal, Complete, and Verifiable example and update the question. I strongly assume that just replacing backslashes is a terrible approach. Commented Apr 3, 2018 at 9:33
  • What do you want to get? You should not mess with the value returned by JSON.stringify() or you won't be able to decode it back (because you'll end up with invalid JSON). Commented Apr 3, 2018 at 9:46
  • @axiac I ended up editing the JSON result to String then back to JSON. The problem is--yeah I think its invalid now because i got an error. Commented Apr 3, 2018 at 9:55
  • JSON is a text representation of some data structure. Think of it as an encoded data (or encrypted, if you like it more). It is not something you can edit. Only JSON.parse() knows how to decode it, to get back data structures similar to those used to generate the JSON. Commented Apr 3, 2018 at 9:57

1 Answer 1

1

As @str commented right. But if you want to force fully remove these then you need to replace the charecters

response.data = response.data.replace(/\\/g, "");
Sign up to request clarification or add additional context in comments.

8 Comments

@SangramBadi So you agree to fix the source but suggest to fix the symptoms instead? Interesting.
@str as you commented above is correct. but below your comment @dscytheProductions commented as `Its just a sample string inside the JSON. I just want to remove the `
@SangramBadi I have a problem now converting it back to JSON so I can use it as data $scope.treeData = new kendo.data.HierarchicalDataSource({ data: data, //here <------ schema: { model: { children: "Rights" } } });
@dscytheProductions That is exactly why I expected the replace approach to be terrible and asked for a full code example in the first place...
@SangramBadi It is fully working now guys! After studying the JSON format i realized i should not delete the (quotation marks). Thanks everyone! Cheers!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.