title: Difficulty when constructing a nested data structure
body: <p>While trying to create a JSON message for an API, I found myself struggling to do something that I thought would be simple. I needed to create a message like the following:</p>
  
  <pre><code>{ "list": [ { "foo": 1, "bar": 2 } ] }
  </code></pre>
  
  <p>However, my first attempt did not work:</p>
  
  <pre><code>say to-json { foo =&gt; [ { a =&gt; 1, b =&gt; 2 } ] };
  # {"foo":[{"a":1},{"b":2}]}
  </code></pre>
  
  <p>Trying to simplify things further confused me more:</p>
  
  <pre><code>say { foo =&gt; [ { a =&gt; 1 } ] };
  # {foo =&gt; [a =&gt; 1]}
  # Note that this is not JSON, but I expected to see curly braces
  </code></pre>
  
  <p>Then I tried to use some temporary variables, and that worked:</p>
  
  <pre><code>my @list = { a =&gt; 1 };
  say to-json { foo =&gt; @list };
  # {"foo":[{"a":1}]}
  
  my %hash = ( a =&gt; 1 );
  say to-json { foo =&gt; [ %hash ] };
  # {"foo":[{"a":1}]}
  </code></pre>
  
  <p>What's going on here?</p>
  
  <p>And is there a way I can achieve my desired output without an extra temporary variable?</p>