<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Jesse,<div class=""><br class=""></div><div class="">You probably want to output the raw JSON in your view. Rails HTML escapes it by default for safety:</div><div class=""><br class=""></div><div class=""> <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/OutputSafetyHelper.html#method-i-raw" class="">http://api.rubyonrails.org/classes/ActionView/Helpers/OutputSafetyHelper.html#method-i-raw</a><br class=""><div class=""><br class="webkit-block-placeholder"></div><div class="">Try something like this:</div><div class=""><br class=""></div><div class=""><%= raw JSON.pretty_generate @jsonish %></div><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class="">Yours,<br class="">Craig | <a href="http://barkingiguana.com/" class="">http://barkingiguana.com/</a><br class="">--<br class="">Barking Iguana Ltd. is a company registered in England and Wales.<br class="">Registered number: 08915147. Registered address: Jubilee House, East Beach, Lytham, St. Annes, Lancashire, England, FY8 5FT.</div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 9 Jun 2016, at 13:56, Jesse Waites <<a href="mailto:jesse.waites@gmail.com" class="">jesse.waites@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thanks Oto! <div class=""><br class=""></div><div class="">So strange... </div><div class=""><br class=""></div><div class=""><div class="">def make_jsonish(array)</div><div class=""> elements = array.each_with_index.map { |num, i|</div><div class=""> { key: i, value: num}</div><div class=""> }</div><div class=""><br class=""></div><div class=""> end</div></div><div class=""><br class=""></div><div class="">without json pretty generate now is:</div><div class=""><br class=""></div><div class="">@jsonish: [{:key=>0, :value=>5}, {:key=>1, :value=>3}, {:key=>2, :value=>2}]<br class=""></div><div class=""><br class=""></div><div class="">In the page source, it is:</div><div class=""><br class=""></div><div class=""><table class=""><tbody class=""><tr class=""><td class="">var dataset =</td></tr><tr class=""><td class="" value="63"><br class=""></td><td class=""> [{:key=>0, :value=>5}, {:key=>1, :value=>3}, {:key=>2, :value=>2}] ;<br class=""><br class=""><br class=""></td></tr></tbody></table>which is the greater than sign in HTML. So weird!!!</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Jun 9, 2016 at 2:20 AM, Oto Brglez <span dir="ltr" class=""><<a href="mailto:otobrglez@gmail.com" target="_blank" class="">otobrglez@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Hey!<div class=""><br class=""></div><div class="">Loose "<font color="#212121" face="helvetica neue, helvetica, arial, sans-serif" class=""><span style="line-height:1.5" class="">JSON.pretty_generate" at the and </span>new-lines<span style="line-height:1.5" class=""> will go away.</span></font></div><div class=""><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5" class=""><br class=""></span></div><div class=""><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5" class="">Cheers!</span></div><span class="HOEnZb"><font color="#888888" class=""><div class=""><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5" class=""><br class=""></span></div><div class=""><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5" class="">- Oto</span></div></font></span></div><div class="HOEnZb"><div class="h5"><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Jun 8, 2016 at 11:53 PM Jesse Waites <<a href="mailto:jesse.waites@gmail.com" target="_blank" class="">jesse.waites@gmail.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">Update: I tried it with Tom's pretty generate JSON method and am a little closer - @jsonish is now:<div class=""><br class=""></div><div class=""><span style="color:rgb(51,51,51);font-family:verdana,arial,helvetica,sans-serif;font-size:13px;line-height:18px" class="">@jsonish: "[\n {\n \"key\": 0,\n \"value\": 5\n },\n {\n \"key\": 1,\n \"value\": 3\n },\n {\n \"key\": 2,\n \"value\": 2\n }\n]"</span><br class=""></div><div class=""><span style="color:rgb(51,51,51);font-family:verdana,arial,helvetica,sans-serif;font-size:13px;line-height:18px" class=""><br class=""></span></div><div class=""><span style="color:rgb(51,51,51);font-family:verdana,arial,helvetica,sans-serif;font-size:13px;line-height:18px" class="">So looks like I need to strip the new lines out? Or rather, not put them in in the first place? Its good to know I was close in my solution path. </span></div></div><div class="gmail_extra"></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Jun 8, 2016 at 1:03 PM, John Cinnamond <span dir="ltr" class=""><<a href="mailto:jc@panagile.com" target="_blank" class="">jc@panagile.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><img style="border:none;background:none;width:0;min-height:0" src="https://welovepg.polymail.io/v2/z/a/NTc1ODRlZjcyMjhh/us2rHmsD3TsNgdd9TPWvQekkJkmoPlftRS-U7MLA3nXNcdOBglpQM6GzoEw_FyBdNk0dKV2FcEgCi12gF0VdfJMoh36lNC89fBXnzPe1lbDkilafd0HK_j2UpDCRdwZA3Jtn7U3PfeY9Onzlvmk=.png" alt="" width="0px" height="0px" border="0" class="">As an aside, `map` returns an enumerator if you don’t give it a block, and enumerators have a `with_index` method. So instead of:<div class=""><br class=""></div><div class=""> array.each_with_index.map { |value, idx| … }</div><div class=""><br class=""></div><div class="">You can say:</div><div class=""><br class=""></div><div class=""> array.map.with_index { |value, idx| … }<br class=""><br class=""><div class=""><div class="">This only saves you 5 characters, but I think it makes the intent slightly clearer.</div><div class=""><br class=""></div><div style="font-size:10px;color:#7e8f9f" class=""></div></div></div><div class=""><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, 08 Jun 2016 at 17:57 Tom Stuart <u class=""></u> <<a href="mailto:Tom+Stuart+%3Ctom@codon.com%3E" target="_blank" class="">Tom Stuart <u class=""></u></a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p class="">On 8 Jun 2016, at 14:32, Jesse Waites <<a href="mailto:jesse.waites@gmail.com" target="_blank" class="">jesse.waites@gmail.com</a>> wrote:<br class="">> def make_jsonish(array)<br class="">> array.each_with_index do |num, i|<br class="">> puts "{ key: #{i}, value: #{num}},"<br class="">> end<br class="">> end<br class=""><br class="">This looks pretty close to being right, but you want to return a string by joining all the individual lines, not print them out. For example:<br class=""><br class="">def make_jsonish(array)<br class=""> array.each_with_index.map { |num, i|<br class=""> "{ key: #{i}, value: #{num}},"<br class=""> }.join("\n")<br class="">end<br class=""><br class="">Less significantly, it would be better to rely on Ruby to turn the resulting data structure (including enclosing square brackets) into JSON for you, so that you’re not responsible for the conversion yourself:<br class=""><br class="">def make_jsonish(array)<br class=""> elements = array.each_with_index.map { |num, i|<br class=""> { key: i, value: num}<br class=""> }<br class=""> JSON.pretty_generate(elements)<br class="">end<br class=""><br class="">Cheers,<br class="">-Tom<br class="">_______________________________________________<br class="">Chat mailing list<br class=""><a href="mailto:Chat@lists.lrug.org" target="_blank" class="">Chat@lists.lrug.org</a><br class="">Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" target="_blank" class="">http://lists.lrug.org/pipermail/chat-lrug.org</a><br class="">Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" target="_blank" class="">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br class="">List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank" class="">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br class=""></p><div class=""></div></blockquote></div><br class=""></div></div></div><br class="">_______________________________________________<br class="">
Chat mailing list<br class="">
<a href="mailto:Chat@lists.lrug.org" target="_blank" class="">Chat@lists.lrug.org</a><br class="">
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank" class="">http://lists.lrug.org/pipermail/chat-lrug.org</a><br class="">
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank" class="">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br class="">
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank" class="">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br class="">
<br class=""></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div></div><div class="gmail_extra">-- <br class=""><div data-smartmail="gmail_signature" class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class="">Jesse Waites</div><div class=""><a href="http://jessewaites.com/" target="_blank" class="">JesseWaites.com</a></div></div></div></div></div></div>
</div>
_______________________________________________<br class="">
Chat mailing list<br class="">
<a href="mailto:Chat@lists.lrug.org" target="_blank" class="">Chat@lists.lrug.org</a><br class="">
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank" class="">http://lists.lrug.org/pipermail/chat-lrug.org</a><br class="">
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank" class="">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br class="">
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank" class="">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br class="">
</blockquote></div>
</div></div><br class="">_______________________________________________<br class="">
Chat mailing list<br class="">
<a href="mailto:Chat@lists.lrug.org" class="">Chat@lists.lrug.org</a><br class="">
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank" class="">http://lists.lrug.org/pipermail/chat-lrug.org</a><br class="">
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank" class="">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br class="">
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank" class="">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br class="">
<br class=""></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class="">Jesse Waites</div><div class=""><a href="http://jessewaites.com/" target="_blank" class="">JesseWaites.com</a></div></div></div></div></div></div>
</div>
_______________________________________________<br class="">Chat mailing list<br class=""><a href="mailto:Chat@lists.lrug.org" class="">Chat@lists.lrug.org</a><br class="">Archives: http://lists.lrug.org/pipermail/chat-lrug.org<br class="">Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org<br class="">List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org<br class=""></div></blockquote></div><br class=""></div></body></html>