title: Convert string to JSON in Freemarker
body: <p>Any ways on how we can convert <code>VALID JSON STRING</code> to actual JSON(sequence) in <code>freemarker</code>. I mean this string is actually returned by a <code>JSON.stringify()</code> call.</p>
  <p>I follow what this <a href="https://stackoverflow.com/questions/13087436/freemarker-parse-a-string-as-json">post</a> says but it seems this is not applicable to mine.</p>
  <pre><code>&lt;#assign test = &quot;(record.custpage_lineitems?json_string)&quot;&gt;
  &lt;#assign m = test?eval&gt;
  
  &lt;#list m as k&gt;
      ${k.item}
  &lt;/#list&gt;
  ERROR says
  Expected collection or sequence. m evaluated instead to freemarker.template.SimpleScalar on line 286, column 32 in template.
  Sample JSON String
  {
  &quot;34952&quot;: {
      &quot;item&quot;: &quot;TRAVEL&quot;,
      &quot;notes&quot;: &quot;Travel Time To Client Site to Perform Repairs.1.0&quot;,
      &quot;type&quot;: &quot;Service&quot;
  },
  &quot;34963&quot;: {
      &quot;item&quot;: &quot;MECHANIC RECOMMENDATION&quot;,
      &quot;notes&quot;: &quot;MECHANIC RECOMMENDATION\nr&amp;r drive tires 21x7x15 smooth black \nr&amp;r lp tank latch on bracket \nr&amp;r lp hose cupler&quot;,
      &quot;type&quot;: &quot;Service&quot;
  },
  &quot;9938&quot;: {
      &quot;item&quot;: &quot;T1&quot;,
      &quot;notes&quot;: &quot;Field Service Call Charge75$ labor 124$&quot;,
      &quot;type&quot;: &quot;Service&quot;
  },
  &quot;34549&quot;: {
      &quot;item&quot;: &quot;GENERAL SERVICE INFO&quot;,
      &quot;notes&quot;: &quot;SERVICE NOTES:\ndrove to customer location found lift found to broken hydraulic hoses had to remove attachment in order to remove broken hoses then drove to get hoses made installed hoses back on lift re installed loose brackets I found out attachment back on lift topped off hydraulic resivoir and lift was ready&quot;,
      &quot;type&quot;: &quot;Service&quot;
  },
  &quot;36264&quot;: {
      &quot;item&quot;: &quot;FSO PARTS (UN CHECK IF NEEDED)&quot;,
      &quot;notes&quot;: &quot;MARK CHECK IF PARTS NOT NEEDED.&quot;,
      &quot;type&quot;: &quot;Service&quot;
  },
  &quot;36266&quot;: {
      &quot;item&quot;: &quot;FSO QUOTE (UN CHECK IF NEEDED)&quot;,
      &quot;notes&quot;: &quot;MARK CHECK IF QUOTE NOT NEEDED.&quot;,
      &quot;type&quot;: &quot;Service&quot;
  },
  &quot;29680&quot;: {
      &quot;item&quot;: &quot;0199992-HY32F&quot;,
      &quot;notes&quot;: &quot;2 x 0199992-HY32F&quot;,
      &quot;type&quot;: &quot;Inventory Item&quot;
  }
  </code></pre>
  <p>}</p>
  <p>It seems that it is not converting to a valid sequence because if i'll try to print <code>${m}</code> it displays the escaped json string.</p>
  <p>I am looking for a way that I will just say <code>&lt;#assign test=toJSON(record.custpage_lineitems)</code> but I think you have to write methods in java since I am doing this in 'netsuite'</p>
  <p>UPDATE: I tried to hard code the json string like</p>
  <pre><code>&lt;#assign m = '{&quot;34952&quot;:{&quot;item&quot;:&quot;TRAVEL&quot;,&quot;notes&quot;:&quot;Travel Time To Client Site to Perform Repairs.1.0&quot;,&quot;type&quot;:&quot;Service&quot;}....}'&gt;
  </code></pre>
  <p>and try to loop through, it seems working. But if I substitute the value of <code>m</code> to <code>myvariable</code> seems not working. I am 100% sure <code>myvariable</code> is not null nor empty but contains the same JSON string.</p>
  <p>My assessment is that, if I could just wrap the <code>myvariable</code> to <code>single quote</code> then I think it will solve the issue. I tried</p>
  <pre><code>&lt;#assign m = 'myvariable'&gt; and
  &lt;#assign m = '(myvariable)'&gt; and 
  &lt;#assign m = '(${myvariable})'&gt; and 
  &lt;#assign m = '(myvariable?string)'&gt; etc.
  </code></pre>
  <p>but none is correct. Can someone just direct me into what is the proper syntax on how to wrap existing variable to single quote.</p>
  <p>Any help guys? Thanks.</p>