use LWP::UserAgent; use JSON; use Data::Dumper; my $url = "http://127.0.0.1:8000/complete/"; my $data = {text => "my word"}; my $ua = LWP::UserAgent->new; # Creating a POST request my $req = HTTP::Request->new(POST => $url); $req->header('Content-Type' => 'application/json'); $req->content(encode_json($data)); # Sending request my $response = $ua->request($req); print Dumper $response; if ($response->is_success) { print "JSON data was successfully returned!\n"; my $content = decode_json($response->content); # Extract the JSON string containing the terms my $json_string = $content->{'response'}{'choices'}[0]{'message'}{'content'}; $json_string = (split "\n\n", $json_string)[0]; # Load the JSON string into a hash my $json_data = decode_json($json_string); # Extract the terms from the hash my $terms = $json_data->{'terms'}; # Print the terms foreach my $term (@$terms) { print "$term\n"; } } else { print "Error: " . $response->status_line . " - " . $response->content . "\n"; }