in reply to Re^3: Int becomes String when I convert to json
in thread Int becomes String when I convert to json

You really do attack the problem. But since I didn't explicitly see it, and am a bad reader, I just want to be sure that implementing...

use Cpanel::JSON::XS::Type; sub makeJSON { (my $hashref) = @_; my $json = encode_json($hashref, {returnvalue => JSON_TYPE_INT, username => JSON_TYPE_STRING, userid => JSON_TYPE_STRING, status => JSON_TYPE_STRING, filename => JSON_TYPE_STRING, rawfilename => JSON_TYPE_STRING, ticket => JSON_TYPE_STRING, message => JSON_TYPE_STRING}); return $json; }

...covers my bases.

Although am still a little offset that sometimes it turned it into a string, and sometimes not. But I'll get over it.

Again, thanks for making slides to let people know.

Replies are listed 'Best First'.
Re^5: Int becomes String when I convert to json
by choroba (Cardinal) on May 10, 2022 at 20:18 UTC
    You also need to
    use Cpanel::JSON::XS;
    Its encode_json takes the extra parameter, the ::Type module just exports the types' names.

    BTW,

    (my $hashref) = @_;
    is usually written
    my ($hashref) = @_;
    so you can easily add more parameters if needed without having to move the parenthesis around.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Yes,

      use Cpanel::JSON::XS;

      was already in there. Just bad cut & pasting. As for:

      (my $hashref) = @_;

      was a typo that seems to work, although I will fix that now. Just to ask tho, is there a reason I shouldn't syntax for single variables?

        I don't understand the question. Are you asking why you shouldn't include my in the parentheses? I've already explained that in my previous post.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]