I'm trying to get the JSON object from a JSON outputted string from a Rails app. Currently in JavaScript I'm doing:
data = "<%= @chromosomes.html_safe %>";
However, since there are quotes at the beginning and end of the JSON object, it is not being rendered as a JSON object. Instead it is doing something like
data = "[{"name":"YHet","organism_id":"4ea9b90e859723d3f7000037"}]"
Is there a way that I can remove the beginning and end quotes so that the object is treated as an array instead of a string?
html_safe
, since he probably wants[{"name":"<script src='badwebsite.com/bad.js'></script>","organism_id":"..."}]
instead of[{"name":"<script src='badwebsite.com/bad.js'></script>","organism_id":"..."}]
. – alpha123 Apr 9 '12 at 15:11organism_id
is a hash or GUID or something else not going to contain < or > or &, andname
probably will be injected into HTML at some point. I'd say escape. – alpha123 Apr 9 '12 at 15:25