How to use JavaScript to parse Ruby JSON string
I am trying to get a JSON object from a JSON output string from a Rails application. Currently in JavaScript I am doing:
data = "<%= @chromosomes.html_safe %>";
However, since there are quotes at the beginning and end of the JSON object, it does not appear as a JSON object. Instead, it does something like
data = "[{"name":"YHet","organism_id":"4ea9b90e859723d3f7000037"}]"
Is there a way to strip the leading and trailing quotes so that the object is treated as an array instead of a string?
+3
source to share