Jmeter Key Extraction value in the response - json

I want to extract the key value generated from response, is there's a way to simulate using JSON Path extractor?
Sample Response:
{
"data": {
"1637042070532561": {
"symbol": "BAUa",
"side": "buy",
"quantity": "1",
"limitPrice": "2145",
"instrumentId": 4,
"created": "1637042070533",
"orderStatus": "rejected",
"type": "limit",
"executions": {
},
"decimals": 2,
"commission": "0",
"currency": "EUR",
"averagePrice": "0",
"id": "1637042070532561",
"filledStatus": "unfilled",
"filledPercent": "0.00",
"filledQty": "0"
}
},
"action": "set-orders",
"type": "orders",
"status": "OK",
"timestamp": "2021-11-16T05:54:30.536Z"
}
Expected Result: 1637042070532561

Go for JSON JMESPath Extractor, it provides keys function allowing querying JSON attribute names, in your case the query would be something like:
keys(data)
Demo:
More information: The JMeter JSON JMESPath Extractor and Assertion: A Guide

Related

How to get the data value in this Json object

I'm working with Flutterwave API and i just don't know what type of Json is this, because this is my first time working with Json and i want to get the value of "data" to Json map or Object
Thanks
{
"data": {
"response_code": "02",
"response_message": "Transaction in progress",
"flw_ref": "MockFLWRef-1676466720721",
"order_ref": "URF_1676466720564_5499435",
"account_number": "0067100155",
"account_status": "active",
"frequency": 1,
"bank_name": "Mock Bank",
"created_at": 1676466720721,
"expiry_date": 1676466720721,
"note": "Mock note",
"amount": "NaN"
},
"message": "Virtual account created",
"status": "success"
}
I want to get "data" value from the Json object to Json map

Convert Nested JSON to Flat JSON using jolt Spec based on multiple inputs (if else)

I need to convert the nested json to flat json by given type of input, if its flat json or nested json gives output as flat json respectively. I haven't seen any correct resource related to the this topic. I given the inputs and outputs below.
I am having some trouble with converting the nested JSON to flat JSON, and didn't get any closer as to what is mentioned problem. I need to transform a JSON structure by using a JOLT spec. I use https://jolt-demo.appspot.com to test the following below. Help me, how can i get the expected out, with this code
Input-1:
{
"MessageType": "CREATION",
"Number": "123",
"Status": "created sucessfully",
"StopSequence": "1",
"Code": [
{
"CodeName": "ABC",
"ShortDescription": "short description about ABC",
"TimeImpact": 234,
"Rank": 1
},
{
"ReasonCodeName": "XYZ",
"ShortDescription": "short description about ABC",
"TimeImpact": 123,
"Rank": 2
}
]
}
Input-2:
{
"MessageType": "UPDATE",
"Number": "345",
"PNumber": "P123",
"Status": "updated sucessfully",
"StopSequence": "2",
"Id": 1234,
"LNumber": "34565",
"DeviceID": "7645235",
"Timestamp": "2015-10-01T16:00:00-05:00",
"Timezone": "US/New_York",
"TimezoneShortName": "EST",
"Unlocode": "XXXX",
}
Expected Output-1 if input 1 passes:
[
{
"MessageType": "CREATION",
"Number": "123",
"Status": "created sucessfully",
"StopSequence": "1",
"Code": "1",
"CodeName": "ABC",
"ShortDescription": "short description about ABC",
"TimeImpact": 234,
"CodeRank": 1
},
{
"MessageType": "CREATION",
"Number": "123",
"Status": "created sucessfully",
"StopSequence": "1",
"Code": "2",
"ReasonCodeName": "XYZ",
"ShortDescription": "short description about ABC",
"TimeImpact": 123,
"Rank": 2
}
]
Expected Output-2 if input 2 passes:
{
"MessageType": "UPDATE",
"PNumber": "P123",
"Status": "updated sucessfully",
"StopSequence": "2",
"Id": 1234,
"Timestamp": "2015-10-01T16:00:00-05:00",
"Timezone": "US/New_York",
}
What you need is to repeat as much as the number of objects of the Code array. So, walk through by them as picking the related values from the out of the array such as
[
{
"operation": "shift",
"spec": {
"Code": {
"*": {
"#(2,MessageType)": "[&1].MessageType", // "#(2,MessageType)" means going up the tree 2 levels to reach the position of "MessageType" , [&1] means combining the values as array of objects depending on the indexes of the array
"#(2,Number)": "[&1].Number",
"#(2,Status)": "[&1].Status",
"#(2,StopSequence)": "[&1].StopSequence",
"#(0,Rank)": "[&1].Code", // to copy the values of the "Rank" to "Code"
"*": "[&1].&"
}
},
"MessageT*|PNu*|St*|Id|Times*|Timezone": "&"
}
}
]

How to print the category value in react native

{
"success": true,
"data": [
{
"price_id": "3",
"product": "456",
"category": "53 Grade Cement",
"brand": "22",
"price": "290",
"price_unit": "bag",
"seller_id": null,
"status": "1",
"created_on": "2021-03-04 00:00:00",
"category_name": "Cement",
"brand_name": "Ramco"
}
]
}
I am guessing you are trying to request some data from server. So you've managed to request and get the data. Assign that data to a variable called response and then
you could just to this response.data[0].category.

Jmeter: JSON response manipulation and passing to the next http request

I've got the response from HTTP GET request as JSON file and I want to use that JSON and pass it to the next HTTP request. I got the following response data
{
"apiInfo": {
"id": "23143",
"name": "bookkeeping",
"state": "used",
"data": "15893712000000"
},
"apiDetails": [
{
"bookName": "abc",
"state": "old",
"noOfTimesUsed": "53"
"additionalParam"{
"name": "abc",
"id": "123"
}
},
{
"bookName": "def",
"state": "new",
"noOfTimesUsed": "5",
"action": "keep"
"additionalParam"{
"name": "def",
"id": "456"
}
},
{
"bookName": "xyz",
"state": "avg",
"noOfTimesUsed": "23"
"additionalParam"{
"name": "ghi",
"id": "789"
}
},
{
"bookName": "pqr",
"state": "old",
"noOfTimesUsed": "75",
"action": "discard"
"additionalParam"{
"name": "jkl",
"id": "012"
}
}
]
}
I want to use "apiInfo" & "apiDetails" part from the JSON response and manipulate its data. As you can notice, some array field have attribute "action" in it and some one doesn't. I want to make sure all the field in the array have this data and is assigned as ' "action":"keep" '. Also, I want to add "id" from apiInfo & "name" from additionalParams from apiDetails itself. The end result I want is somewhat like this
"apiDetails": [
{
"id": "23143",
"bookName": "abc",
"state": "old",
"noOfTimesUsed": "53",
"action": "keep",
"name":"abc"
},
{
"id": "23143",
"bookName": "def",
"state": "new",
"noOfTimesUsed": "5",
"action": "keep",
"name":"def"
},
{
"id": "23143",
"bookName": "xyz",
"state": "avg",
"noOfTimesUsed": "23",
"action": "keep",
"name":"ghi"
},
{
"id": "23143",
"bookName": "pqr",
"state": "old",
"noOfTimesUsed": "75",
"action": "keep",
"name":"jkl"
}
]
I've been trying to use JSR223 sampler and have been struggling with it. It's bit complicated and I need help. P.S.: I've tried using javascript code to manipulate the results as desired but have been unsuccessful.
Please help.
Thanks, Sid
Add JSR223 PostProcessor as a child of the request which returns the above JSON
Put the following code into "Script" area:
def apiDetails = new groovy.json.JsonSlurper().parse(prev.getResponseData()).apiDetails
apiDetails.each { apiDetail ->
apiDetail.put('action', 'keep')
}
vars.put('request', new groovy.json.JsonBuilder(apidetails: apiDetails.collect()).toPrettyString())
That's it, you should be able to refer the generated request as ${request} where required
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

Writing JSON response values from Jmeter to a csv file into separate columns

I need to export the JSON response values in jmeter to a CSV file. The Json response looks somewhat like the sample below. What would be the simplest approach to do this in Jmeter?
{
"messages": null,
"results": {
"aaa": [
{
"code": "123",
"name": "abc",
"primary": true
},
{
"code": "456",
"name": "def",
"primary": false
}
],
"bbb": null,
"ccc": [
{
"code": "789",
"name": "ghi",
"primary": false
},
{
"code": "222",
"name": "jkl",
"primary": true
}
]
},
"errors": null
}
I want the output csv to look something like this:
result, code, name (headers)
aaa, 123, abc
aaa, 456, def
ccc, 789, ghi
Not sure how many variable are there in your JSON but you can try on this website:
http://convertcsv.com/json-to-csv.htm
Usually i do online but putting my JSON format from browser to this link above and get extracted to .CSV
See if that helps, good luck.