title: Using RJSONIO and AsIs class
body: <p>I am writing some helper functions to convert my R variables to JSON.  I've come across this problem: I would like my values to be represented as JSON arrays, this can be done using the AsIs class according to the RJSONIO documentation.</p>
  
  <pre><code>x = "HELLO"
  toJSON(list(x = I(x)), collapse="")
  
  "{ \"x\": [ \"HELLO\" ] }"
  </code></pre>
  
  <p>But say we have a list</p>
  
  <pre><code>y = list(a = "HELLO", b = "WORLD")
  toJSON(list(y = I(y)), collapse="")
  
  "{ \"y\": {\n \"a\": \"HELLO\",\n\"b\": \"WORLD\" \n} }"
  </code></pre>
  
  <p>The value found in y -> a is NOT represented as an array.  Ideally I would have</p>
  
  <pre><code>"{ \"y\": [{\n \"a\": \"HELLO\",\n\"b\": \"WORLD\" \n}] }"
  </code></pre>
  
  <p>Note the square brackets.  Also I would like to get rid of all "\n"s, but collapse does not eliminate the line breaks in nested JSON.  Any ideas?</p>