Jmeter CSV file for Json - json

im new to jmeter.
I'm in need to test the performance of some json requests which normally do some insertion or update in db .
I need to change some record id dynamically . For example
{"columnName":"company","newValue":"cts","oldValue":"","timeStamp":"11-05-2012 14:54:24","version":"1"}],"instruction":"contact_list","**recordId**":"8294547"}]}
i want record id should be dynamically get from csv file. so i did like
"recordid":"$recordid"}
But after HIT TO THE SERVER I found in the request THAT the one more time request id was printing after the json loop ends like
{"columnName":"company","newValue":"cts","oldValue":"","timeStamp":"11-05-2012 14:54:24","version":"1"}],"instruction":"contact_list","recordId":"**8294547**"}]}
8294547
which returns to malformed json request.
can u please tell the way to avoid extra appending recordid after the json loop .
above json is not the actual one just i copied the part i need .

You're missing curly braces. The format for inserting a variable in JMeter is ${myVar}, not $myVar.

Related

JMETER: How to add value from CSV file in Json Extractor?

I want to pass value from my csv file in json extractor but it's not working.
I have tried like [?(#.name == '${UserName}')].id but when i am simply writing Username without taking it from CSV then it is working.
Double check that your UserName variable exists and has the anticipated value using Debug Sampler and View Results Tree listener combination
As long as the associated JMeter Variable exists you should be able to use it in the JSON Extractor

Store json string in txt file or database

Suppose we are getting lots of list data in json format, for every single day the api returns the same data.
Now if I apply the filter on the json then where can I store the API json result for the current day so that there is no need to call the API multiple times.
How can I store it in a txt file or in a database or maybe in cache?
It depends on your aims. You may use a text file or the DB field.
You may use a Redis as a cache.
Try to start with text file at first. Probably it will help you.
1) Draft usage of text (.json) file.
// $json = json_encode($array); // if you don't have json data
$filePath = sprintf('%s_cache.json', date('Y-m-d'));
file_put_contents($filename, $json);
2) Usage of JSON in MySQL
INSERT INTO table VALUES (JSON_OBJECT("key", "value")); // something like this
INSERT INTO table VALUES ('{"key": "value"}'); // or this one
More details about MySQL are here: https://dev.mysql.com/doc/refman/5.7/en/json.html

Read multiple JSONs from single REST Service response and put to Database Table - Talend

I have searched a lot but not found exact slution.
I have a REST service, in response of which I get rows and each row in a JSON, as given bellow:
{"event":"click1","properties":{ "time":"2 dec 2018","clicks":29,"parent":"jbar","isLast":"NO"}}
{"event":"click2","properties":{ "time":"2 dec 2018","clicks":35,"parent":"jbar3","isLast":"NO"}}
{"event":"click3","properties":{ "time":"2 dec 2018","clicks":10,"parent":"jbar2","isLast":"NO"}}
{"event":"click4","properties":{ "time":"2 dec 2018","clicks":9,"parent":"jbar1","isLast":"YES"}}
Each row is a JSON (all are similar to each other). I have a database table having all those fields as columns. I wanted to loop through these and upload all data in Talend. What I have tried is following:
tRestClient--tNormalize--tExtractJsonFields--tOracleOutput
and provided loop criteria and mapping in tExtractJsonFields component but it is not working and throwing me error saying "json can not be null or empty"
Need help in doing that.
Since your webservice returns multiple json objects in the response, it's not valid json but rather a json document.
You need to break it into individual json objects.
You can add a tNormalize between tRESTClient and tExtractJsonFields, and normalize the json document on "\n" character.
The error "json can not be null or empty" is due to an error in your Jsonpath queries. You have to set the loop query to "$", and reference the json properties using "event", "properties.time"
could you try this :
In your tExtractJsonFields, configure the property readBy to JsonPath without loop

How to write a JSON extracted value to a csv file in jmeter for a specific variable

I have a csv file that looks like this:
varCust_id,varCust_name,varCity,varStateProv,varCountry,varUserId,varUsername
When I run the HTTP Post Request to create a new customer, I get a JSON response. I am extracting the cust_id and cust_name using the json extractor. How can I enter this new value into the csv for the correct variable? For example, after creating the customer, the csv would look like this:
varCust_id,varCust_name,varCity,varStateProv,varCountry,varUserId,varUsername
1234,My Customer Name
Or once I create a user, the file might look like this:
varCust_id,varCust_name,varCity,varStateProv,varCountry,varUserId,varUsername
1234,My Customer Name,,,,9876,myusername
In my searching through the net, I have found ways and I'm able to append these extracted variables to a new line but in my case, I need to replace the value in the correct location so it is associated to the correct variable I have set up in the csv file.
I believe what you're looking to do can be done via a BeanShell PostProcessor and is answered here.
Thank you for the reply. I ended up using User Defined Variables for some things and BeanShell PreProcessors for other bits vs. using the CSV.
Well, never tried this. But what you can do is create all these variables and set them to Null / 0.
Once done, update these during your execution. At the end, you can concatenate these with any delimiter (say ; or Tab) and just push in CSV as a single string.
Once you got data in CSV, you can easily split in Ms excel.

Talend - How to output JSON records in multiple rows

I have generated a JSON output using Talend. However, my problem is that all my records are outputed in 1 row in the JSON file. Below is the sample output:
[{"field1":"value1_1","field2":"value2_1","field3":"value3_1"},{"field1":"value1_2","field2":"value2_2","field3":"value3_2"},{"field1":"value1_3","field2":"value2_3","field3":"value3_3"}]
My desired output is to have all JSON record separated by newline in the output file:
[{"field1":"value1_1","field2":"value2_1","field3":"value3_1"},
{"field1":"value1_2","field2":"value2_2","field3":"value3_2"},
{"field1":"value1_3","field2":"value2_3","field3":"value3_3"}]
Thanks in advance for the help!
There is no direct way to do it, but if it's necessary you can re-read the file as raw file using a tFileInputRaw component then replace all },{ by },\n{ in a tJavaRow component.
Use the tFileOutputJSON component, which will help collect the rows as a list into JSON file. You may then use a tFileInput Component to read it and send it as Response.