You might also want to take a look at Data::Clean::JSON which will sanitize things like circular references, regexps, and other "dangerous" stuffs so that the final result is safe to just feed to JSON::encode_json().
Comment on Re: Perl structure to Javacript-ready JSON