bigswifty00000 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

I am trying to send a request to a JSON::RPC server.

One of the parameters is a boolean. I keep getting a malformed Json error.

I've tried a few things and exasperated, I'm asking for thy wisdom!

Thanks in advance!

my $callobj = { "jsonrpc" => "2.0", "id" => 3, method => 'statusTasks2', "params" => { 'history'=>'true', }, };

THE ERROR

{ 'version' => 0, 'content' => { 'jsonrpc' => '2.0', 'error' => { 'data' => 'Invalid JSON was received by the server. An error occurred on the ser +ver while parsing the JSON text.', 'message' => 'Parse error', 'code' => -32700 } }, 'jsontext' => '{"error": {"code": -32700, "data": "Invalid JSON was received by the +server. An error occurred on the server while parsing the JSON text." +, "message": "Parse error" }, "jsonrpc": "2.0" }', 'is_success' => 0 }, 'JSON::RPC::ReturnObject' );

Replies are listed 'Best First'.
Re: encoding a boolean in JSON::RPC::Client
by NetWallah (Canon) on Oct 21, 2015 at 18:52 UTC
    You should probably use JSON::true , instead of 'true'.
    >perl -MJSON -E "say to_json({x=>33, params=>{'history'=>JSON::true}, +})" {"params":{"history":true},"x":33}

            The best defense against logic is ignorance.