Just another Perl shrine | |
PerlMonks |
Translate or morph hash keys to different namesby rmcgowan (Sexton) |
on Nov 06, 2013 at 20:14 UTC ( [id://1061470]=perlquestion: print w/replies, xml ) | Need Help?? |
rmcgowan has asked for the wisdom of the Perl Monks concerning the following question: I'm accessing a REST API interface to an Oracle database. The API is written in Java. The retrieved data is JSON encoded. I cannot make any changes on the server side, and have to live with whatever is sent. There are a number of field and table names that have been changed on the server side for various reasons. For example 'abstract' is 'incidentAbstract', and 'cross_reference' is 'crossReference', in the JSON encoding. I have a number of scripts that have been developed over a decade or more, that use DBI and DBD::Oracle to access data, using the database names. I now need to port these to using the REST API and I'm trying to do this with minimal changes to the scripts themselves. To do this, I need a way to restore the original field or table names for the modified ones in the JSON decoded data. For example:
I found a module on CPAN, Hash::KeyMorpher, that almost does the job, but not quite. It only changes the style of the name, but keeps the name, as in KeyFile to key_file or vice versa. I can write my own, but would like to be sure someone hasn't already done this, or that there isn't a "better way" to handle it. Thanks. updateMany thanks for the pointers to Hash::Map and Data::Visitor::Callback, etc. I had actually looked at Data::Dumper as a potential candidate but decided there might be a "simpler", or at least different, module I could use. It also turns out the JSON modules have a method, filter_json_object, that could also work:
I'll be able to do what's needed with one or another of the suggestions, I've no doubt ;)
Back to
Seekers of Perl Wisdom
|
|