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

I have a json response that I need to get the 'bundleProcessStatus' value to print to file:

$response = { "d" : { "_metadata" : { "apiVersion" : "7.1.0" "operationType" : "Object Perform 11" "security" : { } "pagination" : { "lastPageNum" : 1 "totalItems" : 1 "startIndex" : 1 "endIndex" : 1 "itemsPerPage" : 1 "startIndexForArrays" : 0 "endIndexForArrays" : 0 "currentPage" : 1 } } "response" : [ { "ptoFpngTransactionBundle" : { "bundleProcessStatus" : "SUCCESS" "_metadata" : { } } } ] } }

If I just call print $response the above is what is printed to file. How do I just get the value of "bundleProcessStatus"? Thanks in advance

Replies are listed 'Best First'.
Re: retrieving data from a json response
by ikegami (Patriarch) on Jun 10, 2016 at 18:26 UTC

    If it's encoded using UTF-8,

    use JSON::XS qw( decode_json ); my $data = decode_json($json);

    If the character encoding has already been removed,

    use JSON::XS qw( ); my $data = JSON::XS->new->decode($json);

    Then,

    say $data->{d}{response}[0]{ptoFpngTransactionBundle}{bundleProcessSta +tus};