<div dir="ltr">Note that using raw potentially opens you up to XSS attacks. Although, it depends on how you validate/coerce your data</div><br><div class="gmail_quote"><div dir="ltr">On Thu, Jun 9, 2016 at 10:28 PM Jesse Waites <<a href="mailto:jesse.waites@gmail.com">jesse.waites@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">That did it!!!<div><br></div><div><span style="font-size:12.8px"><%= raw JSON.pretty_generate @jsonish %> has it working perfectly. Thanks so much everyone for your help with this!</span><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 9, 2016 at 9:21 AM, Craig R Webster <span dir="ltr"><<a href="mailto:craig@barkingiguana.com" target="_blank">craig@barkingiguana.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hi Jesse,<div><br></div><div>You probably want to output the raw JSON in your view. Rails HTML escapes it by default for safety:</div><div><br></div><div> <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/OutputSafetyHelper.html#method-i-raw" target="_blank">http://api.rubyonrails.org/classes/ActionView/Helpers/OutputSafetyHelper.html#method-i-raw</a><br><div><br></div><div>Try something like this:</div><div><br></div><div><%= raw JSON.pretty_generate @jsonish %></div><div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><br>Yours,<br>Craig | <a href="http://barkingiguana.com/" target="_blank">http://barkingiguana.com/</a><br>--<br>Barking Iguana Ltd. is a company registered in England and Wales.<br>Registered number: 08915147. Registered address: Jubilee House, East Beach, Lytham, St. Annes, Lancashire, England, FY8 5FT.</div>
</div><div><div>
<br><div><blockquote type="cite"><div>On 9 Jun 2016, at 13:56, Jesse Waites <<a href="mailto:jesse.waites@gmail.com" target="_blank">jesse.waites@gmail.com</a>> wrote:</div><br><div><div dir="ltr">Thanks Oto! <div><br></div><div>So strange... </div><div><br></div><div><div>def make_jsonish(array)</div><div> elements = array.each_with_index.map { |num, i|</div><div> { key: i, value: num}</div><div> }</div><div><br></div><div> end</div></div><div><br></div><div>without json pretty generate now is:</div><div><br></div><div>@jsonish: [{:key=>0, :value=>5}, {:key=>1, :value=>3}, {:key=>2, :value=>2}]<br></div><div><br></div><div>In the page source, it is:</div><div><br></div><div><table><tbody><tr><td>var dataset =</td></tr><tr><td value="63"><br></td><td> [{:key=>0, :value=>5}, {:key=>1, :value=>3}, {:key=>2, :value=>2}] ;<br><br><br></td></tr></tbody></table>which is the greater than sign in HTML. So weird!!!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 9, 2016 at 2:20 AM, Oto Brglez <span dir="ltr"><<a href="mailto:otobrglez@gmail.com" target="_blank">otobrglez@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey!<div><br></div><div>Loose "<font color="#212121" face="helvetica neue, helvetica, arial, sans-serif"><span style="line-height:1.5">JSON.pretty_generate" at the and </span>new-lines<span style="line-height:1.5"> will go away.</span></font></div><div><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5"><br></span></div><div><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5">Cheers!</span></div><span><font color="#888888"><div><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5"><br></span></div><div><span style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;line-height:1.5">- Oto</span></div></font></span></div><div><div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 8, 2016 at 11:53 PM Jesse Waites <<a href="mailto:jesse.waites@gmail.com" target="_blank">jesse.waites@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Update: I tried it with Tom's pretty generate JSON method and am a little closer - @jsonish is now:<div><br></div><div><span style="color:rgb(51,51,51);font-family:verdana,arial,helvetica,sans-serif;font-size:13px;line-height:18px">@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></div><div><span style="color:rgb(51,51,51);font-family:verdana,arial,helvetica,sans-serif;font-size:13px;line-height:18px"><br></span></div><div><span style="color:rgb(51,51,51);font-family:verdana,arial,helvetica,sans-serif;font-size:13px;line-height:18px">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><div class="gmail_quote">On Wed, Jun 8, 2016 at 1:03 PM, John Cinnamond <span dir="ltr"><<a href="mailto:jc@panagile.com" target="_blank">jc@panagile.com</a>></span> wrote:<br><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">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><br></div><div> array.each_with_index.map { |value, idx| … }</div><div><br></div><div>You can say:</div><div><br></div><div> array.map.with_index { |value, idx| … }<br><br><div><div>This only saves you 5 characters, but I think it makes the intent slightly clearer.</div><div><br></div><div style="font-size:10px;color:#7e8f9f"></div></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote"><div dir="ltr">On Wed, 08 Jun 2016 at 17:57 Tom Stuart <u></u> <<a href="mailto:Tom+Stuart+%3Ctom@codon.com%3E" target="_blank">Tom Stuart <u></u></a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p>On 8 Jun 2016, at 14:32, Jesse Waites <<a href="mailto:jesse.waites@gmail.com" target="_blank">jesse.waites@gmail.com</a>> wrote:<br>> def make_jsonish(array)<br>> array.each_with_index do |num, i|<br>> puts "{ key: #{i}, value: #{num}},"<br>> end<br>> end<br><br>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><br>def make_jsonish(array)<br> array.each_with_index.map { |num, i|<br> "{ key: #{i}, value: #{num}},"<br> }.join("\n")<br>end<br><br>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><br>def make_jsonish(array)<br> elements = array.each_with_index.map { |num, i|<br> { key: i, value: num}<br> }<br> JSON.pretty_generate(elements)<br>end<br><br>Cheers,<br>-Tom<br>_______________________________________________<br>Chat mailing list<br><a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br></p><div></div></blockquote></div><br></div></div></div><br>_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div></div><div class="gmail_extra">-- <br><div data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Jesse Waites</div><div><a href="http://jessewaites.com/" target="_blank">JesseWaites.com</a></div></div></div></div></div></div>
</div>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</blockquote></div>
</div></div><br>_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Jesse Waites</div><div><a href="http://jessewaites.com/" target="_blank">JesseWaites.com</a></div></div></div></div></div></div>
</div>
_______________________________________________<br>Chat mailing list<br><a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br></div></blockquote></div><br></div></div></div></div><br>_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div>Jesse Waites</div><div><a href="http://JesseWaites.com" target="_blank">JesseWaites.com</a></div></div></div></div></div></div>
</div>
_______________________________________________<br>
Chat mailing list<br>
<a href="mailto:Chat@lists.lrug.org" target="_blank">Chat@lists.lrug.org</a><br>
Archives: <a href="http://lists.lrug.org/pipermail/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/pipermail/chat-lrug.org</a><br>
Manage your subscription: <a href="http://lists.lrug.org/options.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/options.cgi/chat-lrug.org</a><br>
List info: <a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org" rel="noreferrer" target="_blank">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br>
</blockquote></div>