title: JBuilder dynamic keys for model attributes
body: <p>I'm trying to build a JSON file to access a product's variation via a variation code. Ideally, I could call variations.abcdefgh essentially asking to define a structure like this:</p>
  
  <pre><code>{
     "variations":{
        "abcdefgh":{
           "available":true,
           "price":"12.00"
        },
        "ijklmnop":{
           "available":false,
           "price":"25.00"
        }
     }
  }
  </code></pre>
  
  <p>Doing something in products/show.json.jbuilder like </p>
  
  <pre><code>json.variations @product.variations
  </code></pre>
  
  <p>gives me formatting as such: </p>
  
  <pre><code>{
     "variations":[
        {
           "available":true,
           "price":"12.00",
           "product_code":"abcdefgh"
        },
        {
           "available":true,
           "price":"25.00",
           "product_code":"ijklmnop"
        }
     ]
  }
  </code></pre>
  
  <p>maybe my JavaScript could be better, but I want something a little more accessible based on the product_code. The closest I've gotten has been</p>
  
  <pre><code>@product.variations.each do |variation|
     json.set! variation.product_code, variation
  end
  </code></pre>
  
  <p>but I've yet to find a solution that will put these correctly formatted objects as children into a variations attribute. Anyone run into something similar before?</p>