w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Perl REST Client Module - How to put back entire JSON afer update

Simply update the reference object, and re-encode back to json.

#Update the email attribute value for referenced user object
my $my_new_email = "someone@example.com";
$item->{'profile'}->{'email'} = $my_new_email;

#re-encode as JSON, 
my $json_out = encode_json( $item );

#and PUT the entire record to update it
$cli->PUT( $json_out );

However, you should check to see if the API supports PATCH - this allows you to send back the fields you want updated, without having to do an initial get, you could reduce the above example to:

$cli->PATCH(  '{"id": "abcd1234", "profile":{"email":
"someone@example.com"}}  );

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.