I'm currently evaluating gatling 3.3.1 for a use-case and need to retrieve JSON data from a server, manipulate it and send it back. Unfortunately, I've hit an interesting road block with null values in the response.
I'm using Jackson's ObjectMapper to deserialize and serialize the value to a HashMap[Object,Any]:
scenario("scenario")
.exec(http("get")
.get(url)
.asJson
.check(jsonPath("$").saveAs("json")))
.exec(http("post")
.post(url)
.asJson
.body(StringBody("${json}")))
Here's a website dummy to try it out: https://webhook.site/7130d3d3-ddcc-4c36-8864-c3a6c4c13cf4
The webserver returns:
{
"name": "frodo",
"note": null
}
The gatling script echos back:
{
"name": "frodo",
"note": "null"
}
You see, the note field became "null" instead of the correct null. Why is this happening? Is there a way around it? Am I doing something wrong? Some Jackson option I'm missing?
That's a bug that will be fixed in the next release (3.4.0).
Thanks for reporting but next time, could you please use our bugtracker on Github? :)
Related
I am working on a Power Automate flow to get a JSON file from SharePoint and Parse it. On one of my previous questions I received a solution that worked with a testing JSON file. However when I ran a couple of tests with some JSON files that I need to use, the Parse JSON step gives out errors regarding "missing" required properties.
Basically, the JSON file's arrays do not always have exactly the same elements (properties). For example (below) the element "minimun_version" does not always appear under the element "link", like the image below
and because of this syntax I get the errors below
How can I Parse such a JSON file successfully?
Any idea or suggestion will help me get unstuck.
Thank you
You can allow null values in your Parse Json schema by simply adding that to the schema. April Dunnam has a nice article about this approach:
https://www.sharepointsiren.com/2018/10/flow-parse-json-null-error-fix/
I assume you have something like below in your schema?
"minimum_version": {
"type": "number"
}
You can change that to this to allow null values
"minimum_version": {
"type": [
"number",
"null"
]
}
I tried to design a test script of API Load Testing in JMeter 5.0. Here is my thread group info:
Below is the Body Data, I already added some variables and functions to it. You can also view the sample JSON Body Data at here:
{
"app_name": "Telekom",
"source": "MOENGAGE",
"moe_request_id": "req_${__threadNum}",
"events": [
{
"event_name": "Email Opened",
"event_code": "MOE_EMAIL_OPEN",
"event_uuid": "${__UUID}",
"event_time": ${__jexl3(${__time(,)}/1000,)},
"event_type": "CAMPAIGN_EVENT",
"event_source": "MOENGAGE",
"uid": "${__counter(,)}-${__RandomString(7,ABCDEFG123456)}${uid}",
"email_id": "${email}",
"event_attributes": {
"campaign_id": "${__RandomString(24,abcdefghijklmn123456789)}",
"campaign_name": "July2021_16072021_LigaSuper_English",
"campaign_type": "GENERAL",
"campaign_channel": "EMAIL",
"moe_delivery_type": "One Time",
"moe_campaign_tags": [
"engagement"
],
"moe_campaign_channel": "Email",
"u_em": "${email}"
},
"user_attributes": {
"PRODUCT_TYPE": "Unifi",
"moengage_user_id": "60dc48d4d722040a2e78b788",
"SERVICE_NO": "${uid}",
"id": "${email}"
},
"device_attributes": {}
}
]
}
I also include JSON Extractor to do correlation on the response body:
Here is the results in View Results Tree. Added Debug Sampler to see the whether my parameterization and correlation working or not. Fortunately, only my parameterization is working, while correlation is not.
Updated: This is example of response body:
I want to correlate at "rqUuid": "urn:uuid:1a5d8617-258c-49f7-b1a7-5b8ee71fb9fd" in the response body. Question is, is this the correct way to correlate the JSON Body? Do I need to correlate the response body although I already define the function "event_uuid": "${__UUID}" in the Body Data?
Thanks. Appreciate your help.
You are using a regular expression to get your data from a JSON response using the JSON Extractor. You need to use JSON Path Expressions instead of using regular expressions.
If you want to extract event_uuid from the response, your json path expressions would be events[*].event_uuid
To get the first event_uuid of your events array objects, you can use
events[0].event_uuid
JSON Extractor allows you executing JsonPath queries and it looks like you're trying to use a regular expression there, it will result into a syntax error, you can see jmeter.log file for details:
You're showing us request data and asking about extracting values from the response, in order to be able to help we need to see at least partial (or better full) response data and what part of it do you need.
So far I can only give the following piece of advice: switch to Regular Expression Extractor and there is a chance it will start working without any changes
You can use JSON Extractor or JSON JMESPath Extractor for extracting values from JSON responses.
Your JSON path expression should be responseHeader.rqUuid
You can evaluate the JSON Path expressions or JMESPath expression through the View Result tree or with online tools.
View Result Tree
You can generate the expressions online with http://jsonselector.com/
JMSE Path Evaluator https://jmespath.org
Sample JMX is uploaded to GitHub for your reference https://github.com/pragmatictesters/Pragmatic-Learning-JMeter-Examples/blob/master/TestPlan-StackOverFlow-68706730-JSON.jmx
I would like to know if the following message is well parsed according to json format, I think it is but the application that needs to process it complains about it with the following error
[ERR]tx data JSON file error
The code in the file is this one
{"tx":
{
"moteeui":"fa789f0000000000",
"txmsgid":"000000000152",
"trycount":"5",
"txsynch" : "false",
"ackreq" : "true",
"userdata":
{
"port":"10",
"payload":"ABCABC"
}
}
}
Thanks in advance,
regards!
I have tried also the following snippet
[{
"mote": "202020",
"payload": "ABCB",
"port": 2,
"trycount": 5,
"txmsgid": ""
}]
I have validated with JSONLint and I get an error saying
[ERR]tx data JSON parsing error: 3 object item(s) left unpacked
Does it ring a bell?
Thanks again
Yes, it is correct.
For your info, JSONLint is a good site for checking the validity of JSON.
However, you may want to rethink setting numeric values as strings. ie, it is a better idea to say:
"trycount":5
rather than
"trycount":"5"
As the former indicates to whatever application is consuming the JSON that the value should be parsed as a number.
Similarly with the boolean values, it's better practise to use:
"txsynch" : false
rather than
"txsynch" : "false"
It won't cause an error in your JSON parser to pass these as strings, it is just better practise.
The error in the parser could be for many different reasons.
I want to know if the next value is valid as a JSON format
1223452234
I am using AFNetworking in my iOS app and allow the parse of it with
readingOptions: .AllowFragments
And it works... but it is a valid JSON? what's the name of that kind of things?
Thanks
To my knowledge you must be in an array or object type for the root element.
This means you could have something like this if you really wanted it to be as "small and simple" as possible.
[
12341234
]
or this if you need keys.
{
"test": 321321312
}
I don't think the numbers by themselves are valid and they're definitely not standard.
In JMeter, I need to extract some fields (City, Classification, and Chain) from a JSON response:
{
"StoreCode": "111243",
"StoreName": "Spencer - Sec 14 Gurgaon",
"Address1": "Gurgaon-Sector-14",
"Address2": "NCR",
"Pin": "110000",
"City": "NCR",
"Classification": "Vol 4",
"Chain": "Spencers",
"Version": "20281",
"VisitType": "Weekly"
}
Can it be done using the regular expression extractor? Is there another option?
If this piece of JSON is the all the response - it makes sense to use Regular Expression Extractor.
If you receive larger or more complicated structure - it's better to use special JSON Path Extractor available through plugin. JSON Path expressions for your JSON response would be something like $.City, $.Chain, etc.
See "Parsing JSON" chapter of Using the XPath Extractor in JMeter guide for more details on JSON Path language and on how to install the plugin.
Very easy with the plugin mentioned. See this for example. Here is link to plugin.
My biggest thing to understand was the flow. In your jmeter test you need to have an httprequest that returns data (in this case json data). So running your test you'd see json in the Response Data tab if you have a View Results Tree listener going. If you have this right click on the HttpRequest you want data from. ADD => Post Processors => jp#gc - JSON Path Extractor. Inside that extractor, you can name it anything you want.
The variable name should be one you already have defined in a User Defined Variables config element. The JSON Path would start with a dollar sign, then a dot, then the name of the key you want the value for from your json. So for me: $.logId the value from ... "logId": 4, ... in my json. It will store the number 4 in my userdefined variable. The default value can be set to something you'd never see like -1 or null or false etc...
BTW you reference your variable in your tests with ${variablename}. If putting into json and its a string do "${variablename}". Hope it helps.
Lots of the way to find out with the help of regular expression. Sharing one of them.
"City": "(.*)",
"Classification": "(.*)",
"Chain": "(.*)",