You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Sriharsha Setty <sr...@gmail.com> on 2010/07/29 12:18:55 UTC

Sending a JSON snippet as POST payload

Hi Jmeter users,

I am trying load test a CouchDB cluster by adding new documents and
retrieving them.  Now CouchDB accepts document additions through a JSON
snippet sent a s POST payload.  Now I wish to create the JSON snippet (on
the fly)  by parsing a CSV dataset that I have and then send that to the
CouchDB server as POST payload.  Has anyone tried this before?

What is the best way to configure Jmeter to send and receive JSON?

Your help will be appreciated.

Thanks in advance,
/harsha

Re: Sending a JSON snippet as POST payload

Posted by Deepak Shetty <sh...@gmail.com>.
sure . BSF Pre Processors/ Samplers / Javascript functions all let you write
javascript code that can interact with some of the JMeter objects. BSH is
good if you are a java programmer (and want something verified quickly)

regards
deepak

On Fri, Jul 30, 2010 at 2:48 AM, Sriharsha Setty
<sr...@gmail.com>wrote:

> Hi Deepak,
>
> On Fri, Jul 30, 2010 at 3:59 AM, Deepak Shetty <sh...@gmail.com> wrote:
>
>
> > 3. Use an HTTPSampler. In the parameter section keep the name field
> blank.
> > In value use ${variableName} (Defined in step 1) . So in value you would
> >
> have something like
> > {"attr1":${var1},"attr2":"${var2}",${var3}=["${var4}","${var5}"]} etc etc
> .
> >
>
> Thank you. This solution worked for me. I am able to send hand crafted JSON
> requests my CouchDB document store.
>
>
> > For complex cases you might have to use beanshell
> >
>
> I am not very familiar with BeanShell. Is it possible to do scripting with
> Javascript as mentioned here:
> http://jakarta.apache.org/jmeter/usermanual/best-practices.html
>
> Thanks,
> /harsha
>

Re: Sending a JSON snippet as POST payload

Posted by Sriharsha Setty <sr...@gmail.com>.
Hi Deepak,

On Fri, Jul 30, 2010 at 3:59 AM, Deepak Shetty <sh...@gmail.com> wrote:


> 3. Use an HTTPSampler. In the parameter section keep the name field blank.
> In value use ${variableName} (Defined in step 1) . So in value you would
>
have something like
> {"attr1":${var1},"attr2":"${var2}",${var3}=["${var4}","${var5}"]} etc etc .
>

Thank you. This solution worked for me. I am able to send hand crafted JSON
requests my CouchDB document store.


> For complex cases you might have to use beanshell
>

I am not very familiar with BeanShell. Is it possible to do scripting with
Javascript as mentioned here:
http://jakarta.apache.org/jmeter/usermanual/best-practices.html

Thanks,
/harsha

Re: Sending a JSON snippet as POST payload

Posted by Deepak Shetty <sh...@gmail.com>.
hi
1. Use CSV Data Set Config. This will let you define variables which
correspond to columns. Every iteration will have the variables take the
values of the next row
2. if simple , you can directly do this in the HTTP sampler
3. Use an HTTPSampler. In the parameter section keep the name field blank.
In value use ${variableName} (Defined in step 1) . So in value you would
have something like
{"attr1":${var1},"attr2":"${var2}",${var3}=["${var4}","${var5}"]} etc etc .
For complex cases you might have to use beanshell

regards
deepak

On Thu, Jul 29, 2010 at 2:54 PM, Sriharsha Setty
<sr...@gmail.com>wrote:

> Hi Deepak,
>
> On Fri, Jul 30, 2010 at 3:02 AM, Deepak Shetty <sh...@gmail.com> wrote:
>
> > Can be done using the standard HTTPSampler.
> > If your objects are complex use something like
> http://www.json.org/java/to
> > get your objects and String alongwith Beanshell in Jmeter to dynamically
> > add
> > your values to the sampler otherwise you can manipulate strings yourself
> >
> >
>
> I am new to Jmeter and still getting used to it.  My JSON snippet is not
> very complex. I want to construct key/value pairs (JSON) from a CSV file,
> convert it to JSON payload and send it as POST payload.
>
> I gave a try loading my CSV using the CSV Data Set documented on the
> website, but I was unsuccessful.
>
> Is it possible to do something like this :
>
> 1. For every POST request, pick up a row from the CSV file
> 2. Convert this row to a JSON payload.
> 3. Ask Jmeter to use this as POST data.
>
> That's how I imagine it should be done.  Is this wrong?
>
> Thanks,
> /harsha
>

Re: Sending a JSON snippet as POST payload

Posted by Sriharsha Setty <sr...@gmail.com>.
Hi Deepak,

On Fri, Jul 30, 2010 at 3:02 AM, Deepak Shetty <sh...@gmail.com> wrote:

> Can be done using the standard HTTPSampler.
> If your objects are complex use something like http://www.json.org/java/to
> get your objects and String alongwith Beanshell in Jmeter to dynamically
> add
> your values to the sampler otherwise you can manipulate strings yourself
>
>

I am new to Jmeter and still getting used to it.  My JSON snippet is not
very complex. I want to construct key/value pairs (JSON) from a CSV file,
convert it to JSON payload and send it as POST payload.

I gave a try loading my CSV using the CSV Data Set documented on the
website, but I was unsuccessful.

Is it possible to do something like this :

1. For every POST request, pick up a row from the CSV file
2. Convert this row to a JSON payload.
3. Ask Jmeter to use this as POST data.

That's how I imagine it should be done.  Is this wrong?

Thanks,
/harsha

Re: Sending a JSON snippet as POST payload

Posted by Deepak Shetty <sh...@gmail.com>.
Can be done using the standard HTTPSampler.
If your objects are complex use something like http://www.json.org/java/ to
get your objects and String alongwith Beanshell in Jmeter to dynamically add
your values to the sampler otherwise you can manipulate strings yourself

regards
deepak

On Thu, Jul 29, 2010 at 3:18 AM, Sriharsha Setty
<sr...@gmail.com>wrote:

> Hi Jmeter users,
>
> I am trying load test a CouchDB cluster by adding new documents and
> retrieving them.  Now CouchDB accepts document additions through a JSON
> snippet sent a s POST payload.  Now I wish to create the JSON snippet (on
> the fly)  by parsing a CSV dataset that I have and then send that to the
> CouchDB server as POST payload.  Has anyone tried this before?
>
> What is the best way to configure Jmeter to send and receive JSON?
>
> Your help will be appreciated.
>
> Thanks in advance,
> /harsha
>