Re: need guidance on encode JSON and sorting

2012-02-06 Thread Igor Dovgiy
That's what the documentation says:
...
$json = $json-canonical([$enable])
If $enable is true (or missing), then the encode method will output JSON
objects by sorting their keys. This is adding a comparatively high
overhead.
...

So I guess you'd have to use something like that:

my $ret_json = JSON::XS-new-canonical()-encode($tmp_hash);

-- iD

2012/2/6 Rajeev Prasad rp.ne...@yahoo.com

 i changed and not getting error anymore but the list is still not
 sorted.


 my $json = JSON::XS-new;
 $json-get_canonical;
 $return_json_text = $json-encode ($tmp_hash);
 ---no error, but does not produce sorted output


 the key is a datetime field e.g.: 2012-01-20 22:24:36   value is some
 text




 - Original Message -
 From: Rajeev Prasad rp.ne...@yahoo.com
 To: perl list beginners@perl.org
 Cc:
 Sent: Sunday, February 5, 2012 10:20 PM
 Subject: Re: need guidance on encode JSON and sorting

 I tried below but getting err:

 my $json = JSON::XS-new;
 $json-get_canonical;
 $return_json_text = $json-encode $tmp_hash;

 Scalar found where operator expected atscript.pl line 80, near -encode
 $tmp_hash


 ???




 - Original Message -
 From: Rajeev Prasad rp.ne...@yahoo.com
 To: perl list beginners@perl.org
 Cc:
 Sent: Sunday, February 5, 2012 10:04 PM
 Subject: need guidance on encode JSON and sorting

 in the script this is all i am using JSON as:

 ...
 use JSON::XS;
 ...
 
 $return_json_text = encode_json $tmp_hash;

 this variable ($return_json_text) is then used to display values. I need
 this to be orderd, but not able to figure how to order the outcome??? I
 read about $enabled = $json-get_canonical on JSON's page but not sure hot
 use it as i do not have $json or such object created. Also I am assuming it
 would be sorted on key field of the JSON hash.

 ty.
 Rajeev

 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/


 --
 To unsubscribe, e-mail: beginners-unsubscr...@perl.org
 For additional commands, e-mail: beginners-h...@perl.org
 http://learn.perl.org/





need guidance on encode JSON and sorting

2012-02-05 Thread Rajeev Prasad
in the script this is all i am using JSON as:

...
use JSON::XS;
...

$return_json_text = encode_json $tmp_hash;

this variable ($return_json_text) is then used to display values. I need this 
to be orderd, but not able to figure how to order the outcome??? I read about 
$enabled = $json-get_canonical on JSON's page but not sure hot use it as i do 
not have $json or such object created. Also I am assuming it would be sorted on 
key field of the JSON hash.

ty.
Rajeev

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: need guidance on encode JSON and sorting

2012-02-05 Thread Rajeev Prasad
I tried below but getting err:

    my $json = JSON::XS-new;
    $json-get_canonical;
    $return_json_text = $json-encode $tmp_hash;

Scalar found where operator expected atscript.pl line 80, near -encode 
$tmp_hash


???




- Original Message -
From: Rajeev Prasad rp.ne...@yahoo.com
To: perl list beginners@perl.org
Cc: 
Sent: Sunday, February 5, 2012 10:04 PM
Subject: need guidance on encode JSON and sorting

in the script this is all i am using JSON as:

...
use JSON::XS;
...

$return_json_text = encode_json $tmp_hash;

this variable ($return_json_text) is then used to display values. I need this 
to be orderd, but not able to figure how to order the outcome??? I read about 
$enabled = $json-get_canonical on JSON's page but not sure hot use it as i do 
not have $json or such object created. Also I am assuming it would be sorted on 
key field of the JSON hash.

ty.
Rajeev

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: need guidance on encode JSON and sorting

2012-02-05 Thread Rajeev Prasad
i changed and not getting error anymore but the list is still not sorted.


    my $json = JSON::XS-new;
    $json-get_canonical;
    $return_json_text = $json-encode ($tmp_hash);  ---no 
error, but does not produce sorted output


the key is a datetime field e.g.: 2012-01-20 22:24:36   value is some text




- Original Message -
From: Rajeev Prasad rp.ne...@yahoo.com
To: perl list beginners@perl.org
Cc: 
Sent: Sunday, February 5, 2012 10:20 PM
Subject: Re: need guidance on encode JSON and sorting

I tried below but getting err:

    my $json = JSON::XS-new;
    $json-get_canonical;
    $return_json_text = $json-encode $tmp_hash;

Scalar found where operator expected atscript.pl line 80, near -encode 
$tmp_hash


???




- Original Message -
From: Rajeev Prasad rp.ne...@yahoo.com
To: perl list beginners@perl.org
Cc: 
Sent: Sunday, February 5, 2012 10:04 PM
Subject: need guidance on encode JSON and sorting

in the script this is all i am using JSON as:

...
use JSON::XS;
...

$return_json_text = encode_json $tmp_hash;

this variable ($return_json_text) is then used to display values. I need this 
to be orderd, but not able to figure how to order the outcome??? I read about 
$enabled = $json-get_canonical on JSON's page but not sure hot use it as i do 
not have $json or such object created. Also I am assuming it would be sorted on 
key field of the JSON hash.

ty.
Rajeev

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/