JSON path evaluation - json

given this node in a json response:
{
"name": "RFM912Feilkode",
"valueCodeableConcept": {
"coding": [
{
"system": "http://xxx/error-code",
"code": "0"
}
],
"text": "OK"
}
I want to verify that the text "OK" is present in Gatling using Scala syntax.
Something (pseudo code ish):
.check(jsonPath("$..valueCodeableConcept.text").is("OK"))
but this does not work. Any tips on how to "hit" the OK value and check if it exists?

Your json isn't valid. Missing curly bracket.
I tried this and all works fine:
.check(jsonPath("$.valueCodeableConcept.text").is("OK"))

If you want to extract some json based on other elements in the json (what you seem to be getting at in the comments on other answers), then you can use filters in the jsonPath like
$.[?(#.name=="RFM912Feilkode")].valueCodeableConcept.text
which will get you the text element from valueCodeableConcept where the associated name is RFM912Feilkode

Related

Jmeter Json Extractor: JSONPath Expression works on evaluators but not inside jmeter?

I'm facing issue with a jsonpath to extract element from json.
Here is an example of the json:
[
{
"idA":"104",
"idB":"2941",
"idC":"13316",
"idE":"13361",
"idF":"12758",
"idG":"12865",
"idH":[
]
},
{
"idA":"104",
"idB":"2941",
"idC":"13317",
"idE":"13362",
"idF":"12759",
"idG":"12866",
"idH":[
"10391"
]
},
{
"idA":"104",
"idB":"2941",
"idC":"13318",
"idE":"13363",
"idF":"12760",
"idG":"12867",
"idH":[
]
}
]
Here is the jsonpath:
$[?(#.idH[0]!=null)]
The goal is to get the element where idH is not null.
It works on few json online evaluators from whom I get what I expected:
[
{
"idA": "104",
"idB": "2941",
"idC": "13317",
"idE": "13362",
"idF": "12759",
"idG": "12866",
"idH": [
"10391"
]
}
]
But it fails on others few online evaluators too, returning for example "An error occurred with JSONPath."
Unfortunately, it doesn't work with Json extractor in Jmeter, because I get the first element of the json, like if the jsonpath would have been $[0]
Any Idea what is the problem here?
Thanks in advance for any help, clue or idea.
For information in case, I use Apache JMeter (5.3)
How about using JSON Extractor which allows executing arbitrary JsonPath queries
You should be able to get the object you're looking for as simple as:
$..[?(#.idH[0])]
Demo:
More information: API Testing With JMeter and the JSON Extractor

Data Factory - Retrieve value from field with dash "-" from JSON file

In my pipeline I reach through REST API using GET request to a 3rd party database. As an output I receive a bunch of JSON files. The number of JSON files I have to download (same as number of iterations I will have to use) is in one of the fields in JSON file. The problem is that the field's name is 'page-count' which contains "-".
#activity('Lookup1').output.firstRow.meta.page.page-count
Data Factory considers dash in field's name as a minus sign, so I get an error instead of value from that field.
{"code":"BadRequest","message":"ErrorCode=InvalidTemplate, ErrorMessage=Unable to parse expression 'activity('Lookup1').output.firstRow.meta.page.['page-count']'","target":"pipeline/Product_pull/runid/f615-4aa0-8fcb-5c0a144","details":null,"error":null}
This is how the structure of JSON file looks like:
"firstRow": {
"meta": {
"page": {
"number": 1,
"size": 1,
"page-count": 7300,
"record-count": 7300
},
"non-compliant-record-count": 7267
}
},
"effectiveIntegrationRuntime": "intergrationRuntimeTest1",
"billingReference": {
"activityType": "PipelineActivity",
"billableDuration": [
{
"meterType": "SelfhostedIR",
"duration": 0.016666666666666666,
"unit": "Hours"
}
]
},
"durationInQueue": {
"integrationRuntimeQueue": 1
}
}
How to solve this problem?
The below syntax works when retrieving the value for a json element with a hyphen. It is otherwise treated as a minus sign by the parser. It does not seem to be documented by Microsoft however I managed to get this to work through trial and error on a project of mine.
#activity('Lookup1').output.firstRow.meta.page['page-count']
This worked for us too. We had the same issue where we couldn't reference an output field that contained a dash(-). We referenced this post and used the square brackets and single quote and it worked!
Example below.
#activity('get_token').output.ADFWebActivityResponseHeaders['Set-Cookie']

How to parse dynamic json reponse and get specific value and pass it as an input to next request

I get .json file as a response from an API and from that file I should parse and fins specific parameter and pass it as an input to the next request, how do I do that using Katalon.
If I say
response = JSON.parse("response.json");
it says it is unable to identify JSON as valid. Can someone help me out with the solution?
Your JSON is invalid, maybe it is a copy-paste issue.
The valid JSON should be
{
"responseStatusCode": "OK",
"data": {
"screenName": "employeeTimeslip",
"screenType": "Redirect",
"searchResultCount": 0,
"rows": [],
"tabs": [],
"searchParams": {
"employeeID": "000092926",
"timeslipNumber": "201900019701"
}
}
}
So, you were missing a "," between "OK" and "data" and two closing curly braces at the end of the file.
You can check JSON files for validity yourself using online JSON validators, for example, this one.
i found a way to read specific parameter from the json response file like below:
val scn = scenario("ClaimSubmission")
.exec(http("request_2")
.post("URL")
.headers(headers_2)
.body(RawFileBody("json file path"))
.check(jsonPath("$..timeslipnumber").find.saveAs("timeslipnumber")))
Timeslip number would be retrieved using : .check(jsonPath("$..timeslipnumber").find.saveAs("timeslipnumber")))

Building json path expression - presence of DOT in attribute name

We are working with a legacy system which gives json responses. We trying to test these json endpoints with jmeter. So, we are trying to use the json path extractor plugin for the purpose. But the structure of the json path is causing an issue in creating json path expressions.
The structure of the json which we are receiving from the server is as follows.
{
"ns9.Shopping": {
"transactionID": "XXXXXNEKIHJO7SRHN1",
"transactionStatus": "Success",
"ns9.shoppingResponseIDs": {
"ns9.owner": "1P",
"ns9.responseId": "abcdefghijklmnop"
},
"ns9.offersGroup": {"ns9.thanksGiving": [
{
"ns9.owner": "DL",
"ns9.retailOffer": [
{
"ns9.offerId": "offer1DL",
"ns9.price": 2639.08,
"ns9.currencyCode": "USD",
"ns9.taxTotal": 961.08,
"ns9.taxCode": "USD",
.........
The presence of . [DOT] in the attribute name is causing issues in my json path expression.
In short, can some one help in finding the "transactionID" from "ns9.Shopping"?
You can try to add Regular Expression Extractor within your HTTP Request element.
Put this regex:
"transactionID": "([a-zA-Z0-9]*)"
I hope this will help you.

Node.js SOAP client parameter formatting

I'm having trouble properly formatting one particular soap parameter using the node-soap module for node.js as a client, to a 3rd-party SOAP service.
The client.describe() for this method says this particular input should be in the shape of:
params: { 'param[]': {} }
I have tried a bunch of different JSON notations to try to fit my data to that shape.
Examples of formats that do NOT work:
"params": { "param": [ {"myParameterName": "myParameterValue"} ] }
"params": [ "param": { "name": "myParameterName", "_": "myParameterValue"} ]
"params": { "param" : [ {"name": "myParameterName", "_": "myParameterValue"} ] }
"params": { "param[]": {"myParameterName": "myParameterValue" } }
"params": { "param[myParameterName]": {"_": "myParameterValue" } }
I must be overlooking something, and I suspect I'm going to feel like Captain Obvious when some nice person points out what I'm doing wrong.
Here is what DOES work, using other soap clients, and how they handle the "named parameter with a value"
soapUI for this method successfully accepts this particular input via XML in the shape of:
<ns:params>
<ns:param name="myParameterName">myParameterValue</ns:param>
</ns:params>
Also, using PHP, I can successfully make the call by creating a stdClass of arrays like so:
$parms = new stdClass;
$parms->param = array(
array(
"name"=>"myParameterName","_"=>"myParameterValue"
)
);
and then eventually passing
'params' => $parms
to the PHP soap client
Many thanks!
To get a better look at what XML was being generated by node-soap, I added a console.log(message) statement to the node_modules/soap/lib/client.js after the object-to-XML encoding. I then began experimenting with various JSON structures to figure out empirically how they were mapping to XML structures.
I found a JSON structure for node-soap to generate the XML in my 3rd-party's required named-parameter-with-value format. I was completely unaware of the "$value" special keyword. Looks like this may have been added in the 0.4.6 release from mid-June 2014. See the change history
"params": [
{
"param": {
"attributes": {
"name": "myParameterName"
},
$value: "myParameterValue"
}
}
]
(note the outer array, which gives me the luxury of specifying multiple "param" entries, which is sometimes needed by this particular 3rd-party API)
generates this XML:
<tns:params>
<tns:param name="myParameterName">myParameterValue</tns:param>
</tns:params>
which perfectly matches the structure in soapUI (which I already knew worked) of:
<ns:params>
<ns:param name="myParameterName">myParameterValue</ns:param>
</ns:params>