Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6708705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:47:31+00:00 2026-05-26T07:47:31+00:00

So I am trying to load test a REST API which returns a JSON

  • 0

So I am trying to load test a REST API which returns a JSON value.

To do that I am creating multiple instances of the perl script.

The Perl script basically calls that URL, and tries to decode_json. Obviously when substantial load is generated, it fails.

Now the problem I face is- An error is displayed on command prompt but does not write that error message in a file.

The error message is

malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "Can't connect to 209...") at json_load_test.pl line 39.

In all the three attempts below line 39 refers to:

decode_json($actual_response);

I am simply running the script on the command prompt as:

perl json_load_test.pl >> logs/output.txt 

I EXPECT THE ERROR MESSAGE TO BE WRITTEN IN “output.txt”

My three failed attempts are as follows.

Attempt 1:

my $ua = LWP::UserAgent->new;
$ua->timeout(3);    
$ua->env_proxy;        
my $response = $ua->get("http://$j_env/jobs/all.json?status=active");
my $actual_response=$response->decoded_content;
decode_json($actual_response);
if ($? == -1)
{print "\n Failed to execute: $!\n"; }

Attempt 2:

my $ua = LWP::UserAgent->new;
$ua->timeout(3);    
$ua->env_proxy;        
my $response = $ua->get("http://$j_env/jobs/all.json?status=active");
my $actual_response=$response->decoded_content;
my $perl_scalar= decode_json($actual_response);
if ($perl_scalar)
{ok(1,"For process $u2 inside counter $counter ");}
else
{ok(0,"FAILED!!! process $u2 inside counter $counter");}

Attempt 3:

my $ua = LWP::UserAgent->new;
$ua->timeout(3);    
$ua->env_proxy;        
my $response = $ua->get("http://$j_env/jobs/all.json?status=active");
my $actual_response=$response->decoded_content;
decode_json($actual_response) or die "FAILED!!!!";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:47:32+00:00Added an answer on May 26, 2026 at 7:47 am

    It looks like your error message is coming from stderr, not stdout. Thus,

    perl json_load_test.pl >> logs/output.txt 2>> logs/errors.txt
    

    Or something to that effect. If you want both in one file:

    perl json_load_test.pl 2>&1 >> logs/output.txt
    

    EDIT:

    If for some reason you wanted to trap the error in the perl and send it to stdout, you could:

    eval {
      decode_json($actual_response);
      1;
    } or do {
      my $e = $@;
      print "$e\n";
    };
    

    EDIT2:

    As daxim points out in the edit notes, Try::Tiny may be simpler:

    use Try::Tiny;
    try {
      decode_json($actual_response);
    } catch {
      print "$_\n";
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple ajax load test script that dynamically creates divs,
I am trying to test that a method to load a UI matrix is
I'm trying to load a jqGrid from json data made via a REST call.
I have a server component that I'm trying to load-test. All connections to the
I am trying to load test a web application that uses SAML for SSO,
I'm trying to load test a WCF REST service. The service takes a single
I have a web service I'm trying to load test. I created a program
I'm trying to load a page that is basically an edit form inside a
I am trying to load test a web application, but I am having a
Last night I did a load test on a site. I found that one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.