Jmeter JSON PATH postprocessor - json

I have my JSON response code as
<script type="text/javascript" id="RequestScript">
var contextpath = 'https://example.com/';
var JSONObject = null;
var XMLString ='';
var pswitchprofiles = new Object();
pswitchprofiles.WLDATAObject =
{
: switchprofile:
: {
: : totalRows:5,
: : moreRows:false,
: : rows:
: : [
: : : {
: : : : id:'1f04b8c7788f47eaba507cd1f01bafd6',
: : : : ex:'N',
: : : : name:'Mahindra'
: : : },
: : : {
: : : : id:'a316419bf71f402cbc3a7af746d80626',
: : : : ex:'N',
: : : : name:'Toyota'
: : : },
: : : {
: : : : id:'1b8f642c00c6469cad1f73829d1b88df',
: : : : ex:'N',
: : : : name:'Renault'
: : : },
: : : {
: : : : id:'df989db921f84dfcac2fb1d4e72c18a3',
: : : : ex:'N',
: : : : name:'Huyndai'
: : : },
: : : {
: : : : id:'43B014C9BF0C1516E0530100007F2995',
: : : : ex:'N',
: : : : name:'Skoda'
: : : }
: : ]
: }
}
;
</script>
I am trying to get the id for the corresponding name.
In JSON PATH postprocessor, if i give $.switchprofile.rows[?(#.name == 'Renault')].id in JSON path expressions, I am not able to get the correct id.
Please help me in getting it. Also, i am not sure if that response is actually JSON.
I am using jmeter 3.0

Your response is not JSON one therefore you won't be able to use JSON Path PostProcessor, you will need to switch to Regular Expression Extractor instead.
The relevant regular expression would look like:
id:'(\w+)',\s.*,\s.*name:'Renault'
Demo:
References:
JMeter: Regular Expressions
Using RegEx (Regular Expression Extractor) With JMeter
Perl 5 Regex Cheat sheet

When i use Regular expression extactor with expression id:'(\w*)',ex:'N',name:'Renault' i am able to get my id properly.
Thanks #Dmitri for your help.

Related

Ideas how to store code snippets/objects (not json) in mongodb?

So let's say I am doing converting csv to json in node.js, and doing mapping between the fields found in the customer's input file and the object that my platform requires, such as:
var objInvoice = {
"id" : guid.create().value,
"financingType" : "scf",
"batchId" : batchId,
"recordTypeCode" : inv.kayittipi,
"buyerReference" : result[0].tedarikcireferans,
"supplierReference" : inv.tedarikcireferans,
"invoiceDate" : moment(inv.faturatarih +"-140000" , "YYMMDD-HHmmss").toISOString(),
"certifiedInvoiceAmount" : inv.odenecekfaturatutar,
"currencyCode" : inv.parabirimi,
"maturityDate" : moment(inv.orjvadetarihi +"-140000" , "YYMMDD-HHmmss").toISOString(),
"correctedMaturityDate" : moment(inv.orjvadetarihi +"-140000" , "YYMMDD-HHmmss").toISOString(),
"originalInvoiceAmount" : inv.orjfaturatutar,
"invoiceNo" : inv.faturano,
"invoiceSerialNo" : inv.faturaserino,
"noterizedDocNo" : inv.belgenoteryevmiyeno,
"hashCode" : inv.hashCode,
"forecastDate" : inv.fiilivadetarihi,
"supplierTaxId" : inv.tedarikcivkn,
"supplierName" : inv.tedarikciadi,
"invoiceType" : inv.faturatipi,
"buyerAccountNumber" : inv.aliciiban,
"buyerTaxId" : inv.alicivkn,
"fiReference" : inv. bankakodu,
"bankBranchCode" : inv.bankasubeno,
"invoiceUploadStatus" : inv.dosyakayitstatu,
"gwCode" : "111110000000",
"gwCodeExplanation" : "",
"invoiceDiscountDate" : null,
"additionalInformation1" : inv.aciklama1,
"additionalInformation2" : inv.aciklama2,
"additionalInformation3" : inv.aciklama3,
"lastModificationDate" : null,
"newInvoiceId" : "00000000-0000-0000-0000-000000000000",
"oldInvoiceId" : "00000000-0000-0000-0000-000000000000",
"supplierIban" : "",
"supplierBankName" : "",
"customUniqueId" : "",
"deductionReason" : "",
"paymentObligationNo" : null,
"deductionAmount" : "",
"sellAmount" : "",
"invoiceAmountWithoutVat" : "",
"uploadDate" : now.toISOString(),
}
but a customer2 may have a different positioned fields,or even different headers in file - such as:
var objInvoice = {
"id" : guid.create().value,
"financingType" : "scf",
"batchId" : batchId,
"recordTypeCode" : inv.element1,
"buyerReference" : result[0].element2,
"supplierReference" : inv.element2,
"invoiceDate" : moment(inv.element3 +"-140000" , "YYMMDD-HHmmss").toISOString(),
"certifiedInvoiceAmount" : inv.element4,
"currencyCode" : inv.element5,
"maturityDate" : moment(inv.element6 +"-140000" , "YYMMDD-HHmmss").toISOString(),
"correctedMaturityDate" : moment(inv.element6 +"-140000" , "YYMMDD-HHmmss").toISOString(),
"originalInvoiceAmount" : inv.element7,
"invoiceNo" : inv.element8,
"invoiceSerialNo" : inv.element9,
"noterizedDocNo" : inv.element10,
"hashCode" : inv.element11,
"forecastDate" : inv.element12,
"supplierTaxId" : inv.element13,
"supplierName" : inv.element14,
"invoiceType" : inv.element15,
"buyerAccountNumber" : inv.element16,
"buyerTaxId" : inv.element17,
"fiReference" : inv. element18,
"bankBranchCode" : inv.element19,
"invoiceUploadStatus" : inv.element20,
"gwCode" : "111110000000",
"gwCodeExplanation" : "",
"invoiceDiscountDate" : null,
"additionalInformation1" : inv.element21,
"additionalInformation2" : inv.element22,
"additionalInformation3" : inv.element23,
"lastModificationDate" : null,
"newInvoiceId" : "00000000-0000-0000-0000-000000000000",
"oldInvoiceId" : "00000000-0000-0000-0000-000000000000",
"supplierIban" : "",
"supplierBankName" : "",
"customUniqueId" : "",
"deductionReason" : "",
"paymentObligationNo" : null,
"deductionAmount" : "",
"sellAmount" : "",
"invoiceAmountWithoutVat" : "",
"uploadDate" : now.toISOString(),
}
so I was thinking if it's possible to store each 'mapping' per customer in mongodb? and pulls the correct objInvoice via customer reference?
The issue is, objInvoice cannot be stored as a json document since it contains variables such as inv.element1.
I've also tried to store as a one big string (I tried with {} and without {} ), I was able to store it fine but when I pulled it from the code and unstringnified it the vars didn't get processed as expected.
Any ideas fellow good programmers?
Or the only way is to store those in seperate js files per customer?
Unfortunately, your data is not even valid Javascript Objects or JSON.
An idea is to convert values, like moment(inv.orjvadetarihi +"-140000" , "YYMMDD-HHmmss").toISOString() which are not valid, into strings (escaping correctly). As a result you will be able to JSON.stringify and JSON.parse. The strings can then be evaluated in your code.
Preprocessing your data to escape non-string values into strings certainly works. You may use regexes.

delete multiple array from collection in mongodb in asp.net core

Below is my json string in MongoDB i want to delete MasterColors Array on MasterColorGuid in Asp.net Core
{
"_id" : ObjectId("595657a00c1ac702f6e4f5cb"),
"IsActive" : true,
"IPAddress" : null,
"CreatedBy" : "46F5C2E8-83F4-4062-8CD7-1B567B303919",
"CreatedDateUtc" : ISODate("2017-06-30T13:51:38.324Z"),
"ModifiedBy" : "46F5C2E8-83F4-4062-8CD7-1B567B303919",
"ModifiedDateUtc" : ISODate("2017-06-30T13:51:38.324Z"),
"WebSiteGuid" : "12E36FB8-D1B5-4172-8144-1176C0AFA82D",
"ProductGuid" : "8D647BE5-8ABC-4AD8-8342-1254C8096DC8",
"ProductName" : "BuiltĀ® Netbook & Laptop Sleeve 9-10\"",
"ProductCode" : "BT-5603",
"MasterColors" : [
{
"MasterColorGuid" : "49e35057-39a6-4772-93c9-fc10aa87eff8",
"SkuGuid" : "C634041D-116E-447A-A806-9CA04E4DA5B4"
},
{
"MasterColorGuid" : "8ae4d05e-96f4-486d-9a2f-b1535f711f9f",
"SkuGuid" : "04A03C81-07BC-4609-9311-C051784B1502"
}
]
}
var collection = _Productcontext.GetCollection(Collection);
var distinct = collection
.Distinct(new StringFieldDefinition("ProductSKUs.VariantName"), filterSelect)
.ToList();
return distinct;

JMeter JSON Path Extractor when a JSON is inside a HTML

I want to pull all the "tcversion_id" values from a json i get in a response, but the tricky part is that the json is inside a javascript tag in a html response. Here's the json part of the response:
<script type="text/javascript">
treeCfg.root_name='Test Project / First Plan (4)(<span
class=\"light_not_run\" title=\"Not Run\">0,
<\/span><span class=\"light_passed\" title=\"Passed\">4,
<\/span><span class=\"light_failed\" title=\"Failed\">0,
<\/span><span class=\"light_blocked\" title=\"Blocked\">0<\/span>)';
treeCfg.root_id=6;
treeCfg.root_href='javascript:SP(6,
0)';
treeCfg.children=
[
: {
: : "spec_order":"1",
: : "node_order":"1",
: : "id":"8",
: : "parent_id":"6",
: : "name":"First Suite",
: : "node_type_id":"2",
: : "tcversion_id":"0",
: : "node_type":"testsuite",
: : "node_table":"testsuites",
: : "children":
: : [
: : : {
: : : : "spec_order":"100",
: : : : "node_order":"1",
: : : : "id":"9",
: : : : "parent_id":"8",
: : : : "name":"First Case",
: : : : "node_type_id":"3",
: : : : "tcversion_id":"10",
: : : : "node_type":"testcase",
: : : : "node_table":"testcases",
: : : : "leaf":true,
: : : : "external_id":"1",
: : : : "version":"1",
: : : : "testlink_node_name":"First Case",
: : : : "testlink_node_type":"testcase",
: : : : "text":"<span class=\"light_passed\" title=\"Passed\" alt=\"Passed\"><b>JM2-1<\/b>:First Case<\/span>",
: : : : "position":"1",
: : : : "href":"javascript:ST(9,10)"
: : : },
: : : {
: : : : "spec_order":"101",
: : : : "node_order":"1",
: : : : "id":"11",
: : : : "parent_id":"8",
: : : : "name":"Second Case",
: : : : "node_type_id":"3",
: : : : "tcversion_id":"12",
: : : : "node_type":"testcase",
: : : : "node_table":"testcases",
: : : : "leaf":true,
: : : : "external_id":"2",
: : : : "version":"1",
: : : : "testlink_node_name":"Second Case",
: : : : "testlink_node_type":"testcase",
: : : : "text":"<span class=\"light_passed\" title=\"Passed\" alt=\"Passed\"><b>JM2-2<\/b>:Second Case<\/span>",
: : : : "position":"1",
: : : : "href":"javascript:ST(11,12)"
: : : },
: : : {
: : : : "spec_order":"102",
: : : : "node_order":"1",
: : : : "id":"17",
: : : : "parent_id":"8",
: : : : "name":"Third Case",
: : : : "node_type_id":"3",
: : : : "tcversion_id":"18",
: : : : "node_type":"testcase",
: : : : "node_table":"testcases",
: : : : "leaf":true,
: : : : "external_id":"3",
: : : : "version":"1",
: : : : "testlink_node_name":"Third Case",
: : : : "testlink_node_type":"testcase",
: : : : "text":"<span class=\"light_passed\" title=\"Passed\" alt=\"Passed\"><b>JM2-3<\/b>:Third Case<\/span>",
: : : : "position":"1",
: : : : "href":"javascript:ST(17,18)"
: : : },
: : : {
: : : : "spec_order":"103",
: : : : "node_order":"1",
: : : : "id":"21",
: : : : "parent_id":"8",
: : : : "name":"Fourth",
: : : : "node_type_id":"3",
: : : : "tcversion_id":"22",
: : : : "node_type":"testcase",
: : : : "node_table":"testcases",
: : : : "leaf":true,
: : : : "external_id":"4",
: : : : "version":"1",
: : : : "testlink_node_name":"Fourth",
: : : : "testlink_node_type":"testcase",
: : : : "text":"<span class=\"light_passed\" title=\"Passed\" alt=\"Passed\"><b>JM2-4<\/b>:Fourth<\/span>",
: : : : "position":"1",
: : : : "href":"javascript:ST(21,22)"
: : : }
: : ],
: : "failed":0,
: : "blocked":0,
: : "passed":4,
: : "not_run":0,
: : "not_available":0,
: : "unknown":0,
: : "all":0,
: : "testcase_count":4,
: : "testlink_node_name":"First Suite",
: : "testlink_node_type":"testsuite",
: : "leaf":false,
: : "text":"First Suite (4)(<span class=\"light_not_run\" title=\"Not Run\">0,<\/span><span class=\"light_passed\" title=\"Passed\">4,<\/span><span class=\"light_failed\" title=\"Failed\">0,<\/span><span class=\"light_blocked\" title=\"Blocked\">0<\/span>)",
: : "position":"1",
: : "href":""
: }
]
;
treeCfg.cookiePrefix='test_exec_build_id_2_';
</script>
Can i actually use the JSON Path Extractor to get these values and if so how?
I don't think you can apply JSONPATHExtractor. Use Regular Expression Extractor with regex as follows:
"tcversion_id""(.*?)",
It yields in 5 values. which you access the specfic value by indexing them as follows:
ID is Reference Name specified in Regular Expression Extractor.
Reference Name - value
ID_1 - 0 (first value)
ID_2 - 10 (second value)
ID_3 - 12 (third value)
... continue till ID_5 (matches are 5)

Extract JSON response in JMeter

I am using JMeter and I want to extract a particular value from a JSON response and use this value in subsequent request. I have the JSON Extractor Plugin installed but I am able to drill down to the JSON value.
Below is an example JSON response captured from JMeter.
while(1);
{
: "results":
: [
: : {
: : : "permissions":
: : : [
: : : ],
: : : "exchangeId":"5wFrZHS8Obbw_JJOsaxy7A",
: : : "documentIncomplete":false,
: : : "dateCreated":1453718307090,
: : : "finalized":false,
: : : "voided":false,
: : : "certified":false,
: : : "dateModified":1453718307090,
: : : "metaData":
: : : [
: : : ],
: : : "documentCreated":false,
: : : "orphaned":false,
: : : "dynamicName":false,
: : : "description":"",
: : : "mode":"ADHOC",
: : : "state":"WITHOUT_DOCUMENT",
: : : "name":"01/25/2016 10:38:21",
: : : "priority":"C"
: : }
: ],
: "responseTime":1453718307090
}
I've tried the below but still can't get the exchangeId:
$.permissions[2].exchangeId
$.while..exchangeId
$.permissions.exchangeId
$.results.permissions.exchangeId
$.while.results.permissions.exchangeId
$.while.results[*].permissions.exchangeId
$.while.results[1].permissions[0].exchangeId
Am I doing something wrong here? Any help here is appreciated, I tried searching and couldn't find anything that relates to my problem.
This is not a valid JSON, go for Regular Expression Extractor instead, the relevant configuration would be:
Reference Name: anything meaningful, i.e. exchangeId
Regular Expression: "exchangeId":"(.+?)"
Template: $1$
You will be able to access extracted value as ${exchangeId} where required.
Demo:
References:
Regular Expressions
Using RegEx (Regular Expression Extractor) with JMeter

How to add Timestamp to Spring-Data-Mongo in Roo?

I have a Spring Roo project I am trying to create based on log4mongo-java appender and I want to get access to the data entries that looks like:
{
"_id" : ObjectId("4f16cd30b138685057c8ebcb"),
"timestamp" : ISODate("2012-01-18T13:46:24.704Z"),
"level" : "INFO", "thread" : "catalina-exec-8180-3",
"message" : "method execution[execution(TerminationComponent.terminateCall(..))]",
"loggerName" :
{ "fullyQualifiedClassName" : "component_logger",
"package" : ["component_logger"],
"className" : "component_logger"
},
"properties" : {
"cookieId" : "EDE44DC03EB65D91657885A34C80595E"
},
"fileName" : "LoggingAspect.java",
"method" : "logForComponent",
"lineNumber" : "81", "class" : {
"fullyQualifiedClassName" : "com.comcast.ivr.core.aspects.LoggingAspect",
"package" : ["com", "comcast", "ivr", "core", "aspects", "LoggingAspect"],
"className" : "LoggingAspect"
},
"host" : {
"process" : "2220#pacdcivrqaapp01",
"name" : "pacdcivrqaapp01",
"ip" : "24.40.31.85"
},
"applicationName" : "D2",
"eventType" : "Development"
}
The timestamp looks like:
"timestamp" : ISODate("2012-01-17T22:30:19.839Z")
How can I add a field in my Logging domain object to map this field?
That's just the JavaScript Date (according to the mongo docs, and as can be demonstrated in the shell), so try with java.util.Date.