I have this array of javascript objects (which are actually musical notes) that are generated in my javascript front-end. In order to store it, I had to run javascript JSON.stringify(objectArray)
before throwing it into a hidden input, but that automatically encases all my keys in double quotes like so:
[
{"class":"barline","symbol":"standard","barline":true,"newSystem":true},
{"class":"note","rhythm":"half","duration":0.5,"symbol":"flag","hand":"R","newbar":true,"rebel":false},
{"class":"note","rhythm":"half","duration":0.5,"symbol":"flag","hand":"R","endbar":true,"rebel":false},
{"class":"barline","symbol":"standard","barline":true},
{"class":"note","rhythm":"half","duration":0.5,"symbol":"flag","hand":"R","newbar":true,"rebel":false}
]
Before filtering my params in Rails, I run JSON.parse(params[:score][:notes])
to turn it from a string into a proper JSON array for storage in MongoDB (I'm specifically using Mongoid)
I know it's normally proper procedure to keep keys in quotes in most cases, but I like using the dot notation for keys to grab values in all my JS.
Should I switch my JS to reference everything with brackets, or can you think of a simple function that would quickly parse out the keys' quotes before sending to the hidden input?