The Rack utils.rb method to_params_hash
does indeed recurse. It does that because, per http://api.jquery.com/jQuery.ajax/ , $.ajax()
treats the data:
variable as a string containing URL query parameters.
Put together, Rails treats each key in your nested structure as something that you want to see in your params
hash. You don't; you just need to pass all that JSON as a string, so your own methods can safely decode it as JSON, using a C JSON library that (probably) won't abuse the stack.
Per jQuery ajax data two variables , you might be able to stuff the string into a hash and pass the hash:
var dataObj = {};
dataObj[json]=JSON.stringify({ sortd_items: sorted_items });
$.ajax({ ... data: dataObj });
Now $.ajax()
won't see a string, won't convert it into query params, and won't bust Rack.