JMeter JSON Path Extractor when a JSON is inside a HTML - json

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)

Related

file_get_contents('php://input'); is not working

$json = file_get_contents('php://input');
is not returning any result
sample JSON I was supposed to get from my payment gateway is here (sorry I couldn't post sample code here please see comment)
https://uat-paco.s3.ap-southeast-1.amazonaws.com/HTML-based-docs/CorePaymentAPI/2022-04-25-Et01x9/APIs/Payment.html#_inline_response_202_data
{
"version" : "1.0.0",
"apiResponse" : {
"responseMessageID" : "fadaba8f-b02c-4ff4-a8f0-2e5ce9873185",
"responseToRequestMessageID" : "e952828c-6d19-4a08-92e4-1bc47e1945a2",
"responseCode" : "PC-B050000",
"responseDescription" : "Success",
"responseDateTime" : "2016-08-29T09:12:34.001+0000",
"responseTime" : 2400,
"marketingDescription" : "Payment is success. Thank you for purchase."
},
"data" : {
"paymentIncompleteResult" : {
"officeGroupId" : "string",
"officeId" : "string",
"transactionDateTime" : "2016-08-29T09:12:34.001+0000",
"orderNo" : "684105191128073630",
"productDescription" : "URRT55",
"invoiceNo2C2P" : "FPX054658",
"pspReferenceNo" : "W32UPVAPCP260543864232",
"controllerInternalID" : "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
"paymentStatusInfo" : {
"paymentStatus" : "A",
"paymentStep" : "PA",
"lastUpdatedDTTM" : "2016-08-29T09:12:35.001+0000"
},
"paymentType" : "CC-VI",
"paymentExpiryDateTime" : "2016-08-30T23:59:59.999+0000",
"channelCode" : "WEBPAY",
"agentCode" : "FPX_SBIA",
"mcpFlag" : "N",
"mcpDetails" : {
"mcpType" : "DCC",
"fxRate" : {
"fxRate" : 32.9,
"markUp" : 1.2,
"convertedAmount" : {
"amountText" : "000000006135",
"currencyCode" : "USD",
"decimalPlaces" : 2,
"amount" : 61.349694
},
"fxProviderId" : "FXP0001",
"fxDate" : "2016-08-29T09:12:34.001+0000"
}
},
"merchantIdForMCP" : "4572325756",
"transactionAmount" : {
"amountText" : "000000999950",
"currencyCode" : "THB",
"decimalPlaces" : 2,
"amount" : 9999.5
},
"settlementAmount" : {
"amountText" : "000000999950",
"currencyCode" : "THB",
"decimalPlaces" : 2,
"amount" : 9999.5
},
"customFieldList" : [ {
"fieldName" : "ExternalID5",
"fieldValue" : "AMADEUS"
} ],
"aresACSChallenge" : {
"transStatus" : "C",
"acsURL" : "https://uatemvco.2c2p.com/challenge",
"creq" : "Base64url encoded form data"
},
"authentication3DSVersion" : "2.1.0",
"availablePaymentTypes" : [ "CC-VI", "CC-CA" ],
"untokenizedStoredCardList" : [ {
"storedCardUniqueID" : "string",
"isExpired" : true,
"cardNumber" : "401200XXXXXX3335",
"cardExpiryMMYY" : "1124",
"cvvCode" : "123",
"payerName" : "Attasit Txxxxxx",
"issuerBankCountry" : "TH",
"issuerBankName" : "JPMORGAN CHASE BANK N.A."
} ]
},
"paymentPage" : {
"paymentPageURL" : "https://demo-paco.2c2p.com/payment/form",
"validTillDateTime" : "2016-08-29T09:12:34.001+0000"
}
}
}

MongoDB aggregation - group and retrieve ohters fileds

i have a collection with this documents:
{
"_id" : BinData(3,"utMu84VFQk+p6LOEE3Ia3w=="),
"DepartDate" : ISODate("2017-08-14T02:00:00.000+02:00"),
"Origin" : {
"Code" : "MIL",
"City" : "Milano",
"Country" : "IT"
},
"Destination" : {
"Code" : "TIA",
"City" : "Tirana",
"Country" : "AL"
},
"ReturnDate" : ISODate("2017-08-21T18:05:00.000+02:00"),
"SearchDate" : ISODate("2017-07-15T02:00:00.000+02:00"),
"Duration" : 150,
"Price" : "376.79",
"PriceCents" : 37679,
"Currency" : "EUR",
},
{
"_id" : BinData(3,"utMu845468+p6Lertya3w=="),
"DepartDate" : ISODate("2017-08-14T02:00:00.000+02:00"),
"Origin" : {
"Code" : "AOI",
"City" : "Ancona",
"Country" : "IT"
},
"Destination" : {
"Code" : "TIA",
"City" : "Tirana",
"Country" : "AL"
},
"ReturnDate" : ISODate("2017-08-21T18:05:00.000+02:00"),
"SearchDate" : ISODate("2017-07-15T02:00:00.000+02:00"),
"Duration" : 100,
"Price" : "376.79",
"PriceCents" : 37679,
"Currency" : "EUR",
},
.........
.........
I want to group by ONLY Destination.City and return an object with
Destination.City, Destination.Code and count. Like this example:
/* 1 */
{
"_id" : {
"Code" : "PMO",
"City" : "Palermo",
"Country" : "IT"
},
"count" : 184564.0
},
/* 2 */
{
"_id" : {
"Code" : "CAG",
"City" : "Cagliari",
"Country" : "IT"
},
"count" : 130873.0
},
......
......
I tried with this query (i use MongoBooster):
db.parsed_data.aggregate([
{ "$match" : { "Destination.Country" : "IT", "Segments" : { "$elemMatch" : { "Carrier" : "AZ" } } } },
{ "$group" : { "_id" : { "City" : "$Destination.City"}, "count" : { "$sum" : 1 } } },
{ "$project" : {"Destination.Code" : 1, "Destination.City" : 1, "Destination.Country" : 1 }},
{ "$sort" : { "count" : -1 } },
{ "$limit" : 9 }])
It returns grouped by City but it shows only the City Name.
In this way:
/* 1 */
{
"_id" : {
"City" : "Lampedusa"
}
},
/* 2 */
{
"_id" : {
"City" : "Trieste"
}
},
This is not correct.
How can i group by ONLY the Destination.City and return an object with
Destination.City, Destination.Code and count?
Thx

Jmeter JSON PATH postprocessor

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.

JsonPath - Extract property by name

I am trying to extract any property name containing "cpu" and "usageRatio" from the following Json using Jayway JsonPath, but so far I have been out of luck.
Checked their documentation and could not find a solution. Any ideas?
To be clear, I would like to extract cpu usage ration for all cpu's in a dynamict fashion (there can be many cores):
{
"entries" : {
"cpu.0_1.user" : {
"lastUpdateMicros" : 1493578024979676,
"value" : 10167446,
"updateType" : "MOVING_AVERAGE"
},
"cpu.0_1.idle" : {
"value" : 277255191,
"lastUpdateMicros" : 1493578024979652,
"updateType" : "MOVING_AVERAGE"
},
"disk.usr.usageRatio" : {
"value" : 0.871294498443604,
"lastUpdateMicros" : 1493578024990246,
"updateType" : "BASIC"
},
"disk.shared.usedSpace" : {
"updateType" : "BASIC",
"lastUpdateMicros" : 1493578024990318,
"value" : 707563520
},
"disk.var.log.availableSpace" : {
"lastUpdateMicros" : 1493578024990355,
"value" : 7224614912,
"updateType" : "BASIC"
},
"disk.usr.local.www.guiserverroot.usr.local.www.guiserver.availableSpace" : {
"value" : 2369658880,
"lastUpdateMicros" : 1493578024990398,
"updateType" : "BASIC"
},
"cpu.0_0.idle" : {
"value" : 265264234,
"lastUpdateMicros" : 1493578024979593,
"updateType" : "MOVING_AVERAGE"
},
"cpu.0_1.usageRatio" : {
"value" : 0.07,
"lastUpdateMicros" : 1493578024979635,
"updateType" : "MOVING_AVERAGE"
},
"cpu.0_0.usageRatio" : {
"lastUpdateMicros" : 1493578024979564,
"value" : 0.12,
"updateType" : "MOVING_AVERAGE"
}
}
Yes, I know the Json structure sucks but sadly I don't have access to change it.
/Patrik

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