json extractor expression to extract field outside array - jmeter

How can I grab productId from the outside array after checking for the condition. I have tried $..items[?(#.stock.available==true)].productId
{
"listings": [
{
"productId": "100-dark-hot-chocolate",
"items": [
{
"stock": {
"available": true
}
}
],
"test": null
}
]
}

This one should give you what you're looking for:
$.listings[*][?(#.items[0].stock.available == true)].productId
Demo:
More information:
JsonPath - Filter Operators
JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

Related

JMeter Script to extract an id from Json response

I need to extract id which as Status 1. How can I achieve it.
Example: id (abc) in below example as its status is 1
''''
{
"Documents": [
{
"id": "abc",
"Status": 1,
},
{
"id": "pgr",
"Status": 2,
},
{
"id": "abc",
"Status": 2,
}
]
}
''''
Thanks
You can do this using JSON Extractor, the relevant JSONPath query would be something like:
$..[?(#.Status == 1)].id
Demo:
More information:
JSONPath Filter Operators
JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios

Dataweave 2 transforming an array of objects having a id field, into a object whose elements are maps

need some suggestion for a dataweave 2 transformation that can transform the following input (Array of Object having an id field) to the following output (grouping in an array the objects sharing the same id into a map, having the id as key).
Input :
[
{
"id": "1117",
"Tot": "10.0",
"Per": "7/2025"
},
{
"id": "1117",
"Tot": "200.0",
"Per": "2/2021"
},
{
"id": "7997",
"Tot": "78.0",
"Per": "10/2023"
}
]
output
{
"1117": [
{
"id": "1117",
"Tot": "10.0",
"Per": "7/2025"
},
{
"id": "1117",
"Tot": "200.0",
"Per": "2/2021"
}
],
"7997": [
{
"id": "7997",
"Tot": "78.0",
"Per": "10/2023"
}
]
}
Any idea?
Thanks
%dw 2.0
output application/json
---
payload groupBy $.id
You just want to group by the ID? There ya go.
I would recommend going to https://developer.mulesoft.com/learn/dataweave and then going to the tutorial tab (top right). It will walk through these basic scenarios :)
payload groupBy $.id
Adding more chars to reach 30.

Apache nifi jolt transform to get only particular key and value

I am very new to Nifi. In Nifi using JoltTransformJson I need to convert following input to below output: Can someone please provide the Jolt specification. I have tried several ways to do this but could not get the same output.
Input
{
"myOps": {
"Ops1": {
"type": "software",
"url": "url-software"
},
"Ops2": {
"type": "hardware",
"url": "url-hardware"
}
}
}
Output
{
"type": "software",
"url": "url-software"
},
{
"type": "hardware",
"url": "url-hardware"
}
You don't need Jolt for this. You can use the EvaluateJsonPath processor with a JsonPath expression of $.myOps.* which will return a valid JSON array containing the two objects you're looking for. JsonPath.com is a good resource for evaluating & debugging JsonPath expressions.
If you have a requirement to avoid the wrapping [] (although that's valid JSON), you can use ReplaceText to remove them.
Check this spec,
[
{
"operation": "shift",
"spec": {
"myOps": {
"Ops*": {
"#": "[]"
}
}
}
}
]

Jmeter - JSON Extractor

I'm trying create a json expression path that returns the id when the reference with {" id ":" 00000000000000000000000004640254 "}. I have tried with
$.[?(#.Relationship[?(#.Ref.id=='00000000000000000000000004640254')])].id
but it doesn't return data
Json message is
[
{
"id": "234567890234567890",
"Relationship": [
{
"type": "Indirect",
"Ref": {"id": "00000000000000000000000004640253_01"}
},
{
"type": "Direct",
"Ref": {"id": "00000000000000000000000004640254"}
}
],
"Specification": {"id": "Gold123AS"}
},
{
"id": "234567890234567891",
"Relationship": [
{
"type": "Indirect",
"Ref": {"id": "00000000000000000000000004640253_02"}
},
{
"type": "Direct",
"Ref": {"id": "00000000000000000000000004640253"}
}
],
"Specification": {"id": "Gold123AS"}
}
]
if someone can help me, thanks
I don't think you can do this using JSON Extractor as returning the parent node is not implemented by underlying JsonPath library
Go for JSR223 PostProcessor and Groovy language instead, the relevant code would be something like:
def json = new groovy.json.JsonSlurper().parse(prev.getResponseData())
0.upto(json.size() -1 , { idx ->
if (json.get(idx).Relationship.find { it.Ref.id.equals('00000000000000000000000004640254') } != null) {
vars.put('id', json.get(idx).id as String)
return
}
})
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It

Jmeter-Regular expression extraction-how to get the value of attribute name

I have the below response from Rest service. I need do capture the value of dSecurityGroup which is "TEST" and pass it to next request. Can yu help on this
"GenericResponse": {
"Service": {
"IdcService": "CHECKIN_UNIVERSAL",
"Document": {
"Field": [
{
"name": "xIPM_APP_1_9:isSetDefault",
"value": "1"
},
{
"name": "IdcService",
"value": "CHECKIN_UNIVERSAL"
},
{
"name": "dSecurityGroup",
"value": "TEST"
},
{
"name": "xIPM_APP_1_6:rule",
"value": "IpmApp_1_Fields_Hide"
},
{
"name": "dpTriggerField",
"value": "xIdcProfile"
},
]
}
}
}
Your JSON response is invalid. check with https://jsonformatter.curiousconcept.com/ and update the correct JSON
Your response is JSON therefore it doesn't make sense to use Regular Expression Extractor.
Consider using JSON Extractor instead, it allows using JsonPath queries which provide handy way to extract the "interesting" values from JSON responses.
In your case the relevant query would be something like:
$..[?(#.name == 'dSecurityGroup')].value
Demo:
More information: API Testing With JMeter and the JSON Extractor

Resources