views:

325

answers:

1

One of the features in Rails 2.3 was json key quoting. I was wondering if there was an easy way to turn the key quoting off or modify the way quoting is done (change to single quotes for example).

I'd like to output a json format that Google's Visualization API will accept (http://code.google.com/apis/visualization/documentation/dev/implementing_data_source.html#examples). The keys don't have quotes.

From the Rails release notes:

If you look up the spec on the “json.org” site, you’ll discover that all keys in a JSON structure must be strings, and they must be quoted with double quotes. Starting with Rails 2.3, we do the right thing here, even with numeric keys.

+1  A: 

This might sound a little silly, but what I did was just modify the Rails' code. It was quick and dirty, and you had to re-apply it at every upgrade, but there didn't seem to be a better way. Good luck!

scraimer
Is there a meta-programming way to do this? I wouldn't want to actually modify the code.
thaiyoshi
I have no idea. I'd suggest looking at the source code and seeing which flags are checked when it decides to do quoting, and see how you can manipulate them. It might be some global setting which you could set and unset around the commands you want to do custom quoting for.
scraimer