Looks like JSON::XS does the job:
use JSON::XS; use Data::Dumper; my %hash = ( cl_ip => 209890 ); my $json = encode_json \%hash; print Dumper( \%hash ); print qq($json\n); __END__ $VAR1 = { 'cl_ip' => 209890 }; {"cl_ip":209890}
Update:
I worry a bit about this. The OP wrote:
"...some strings that were supposed to be converted to integers are still strings...So a data dump looks good: 'cl_ip' => 209889, But there's a string in the json file for this key: "cl_ip":"209889"..."
From the JSON::XS manual:
"...Its primary goal is to be correct..."
The OP expects that the value of cl_ip is an integer after encoding, right?
In my example using JSON::XS the OP gets what he wants (integer).
IMHO JSON::XS works as designed - the result is what the OP expected.
If i still miss something: thanks for any advice.
I hope i didn't miss something. Regards Karl
«The Crux of the Biscuit is the Apostrophe»
In reply to Re: String to Integer, for json file
by karlgoethebier
in thread String to Integer, for json file
by halecommarachel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |