I have the following JSON file which will be passed as a parameter file to an Argo workflow:
{
"keys": [
"key1",
"key2",
"key3"
]
}
Accessing "keys" like '{{inputs.parameters.keys}}' reads keys as a string instead of a list.
Is it possible to read an input parameter from a parameter file as a list of values?
Within an Argo Workflow, parameters are always strings.
You can use expression templates to retrieve information from the stringified list.
value: '{{=jsonpath(inputs.parameters.keys, "$.0")}}' # get the first item
Related
It is possible to get a JSON value by validating with another value.
For example i am getting multiple responses as below;
{
"place_name": "Home",
"selected_icon": "http:\/\/abc.tech\/images\/home_selected.png",
"updated_at": "2017-11-10 12:12:34.795339",
"icon": "http:\/\/abctech\/images\/home.png",
"created_at": "2017-11-10 12:12:34.795339",
"active_flag": 1,
"id": 1
}
I have extract the "place name" using $..place_name. Now validating the place_name i need to extract the icon. Which means i need to save the icon value which matches the "place name" only
Varibale : new
JSON extractor 1 : $..place_name (second value so only using $..)
Varibale : abc
JSON extractor 2:$..[?(#.place_name==${new})].icon
Matc No (o for random): -1
The value is not passing any suggestion
i have tried with this extarctor also JSON extractor 2:$..[?(#.place_name=='${new}')].icon
Match random i am taking as -1 because i am passing the value in for each controller
I don't find any issue with you approach, it is working fine. I have tried with your payload and changed your payload with multiple value. Both are working fine.
With your payload where single place_name is there,
With multiple value for icon:
Passed the value to for each controller
How to extract a item from compose.
For example I have a compose item like below,
How to get "AAAA" only and input create a item to sharepoint List.
I tyied
outputs('Select')?['Title']
Appear Error msg like that "Array elements can only be selected using an integer index."
Compose
{ "Titile" : "AAAA",
"TitleB" : "BBBB",
"TitleC" : "CCCC",
"TitleD" * "DDDD}
Firstly, your JSON is far from being valid so I've made some assumptions and have included it here with what I used for my answer ...
{
"TitleA": "AAAA",
"TitleB": "BBBB",
"TitleC": "CCCC",
"TitleD": "DDDD"
}
My suggestion is that you use variables instead of compose.
Here is my flow ...
With the second step, this is the expression I used ...
variables('Json Object')?['TitleA']
This is the end result ...
Consider the following
{
"foo": [ "cat", "dog" ]
}
I want to replace these values in Octopus with
{
"foo": [ "wolf" ]
}
How do I do it with Octopus? I can't replace with ["wolf"] in the value as I receive an error: Invalid JSON: Expecting ','.
I'm using dotnet core.
How are you replacing the variable value?
This should be possible using Structured Configuration Variables with a variable named foo set to ["wolf"].
I have a JSON response below:
"books": [
{
"name" : "test1",
"id" : "T01"
},
{
"name" : "test2",
"id" : "T02"
},
{
"name" : "test3",
"id" : "T03"
},
]
I am extracting all respective ids and sending it as a body to another request.
Other request takes it as an array of strings but when I am extracting it, it is showing as integers:
Currently it shows: ids_ALL = [T01, T02, T03]
and I have to pass it like: ids_ALL = ["T01", "T02", "T03"]
Note: I am suffixing _ALL to get all ids.
Since it is not passing the array as string, I am getting an error.
Is there away to extract it and put it in array of strings or way to use post-processer and then convert the array and send to other request.
This one-liner will extract all the IDs and generate the JSON Array you're looking for:
vars.put('payload', (new groovy.json.JsonBuilder(new groovy.json.JsonSlurper().parse(prev.getResponseData()).books.id.collect()).toPrettyString()))
no other extractors are needed, you can refer the generated array as ${payload} later on where required
In Taurus it can be put into the JSR223 Block
More information:
Apache Groovy - Parsing and producing JSON
Apache Groovy - Why and How You Should Use It
You can use JSON Extractor or JSON JMESPath Extractor to extract all the ids from the response.
Place a JSR223 Post processor just below the JSON Path Extractor to create a list of Strings (ids)
def idCount=vars.get("booksIds_matchNr").toInteger()
def lstIds=[]
for(i in 1..idCount){
String currentId=vars.get("booksIds_" + i)
lstIds.add("\""+ currentId + "\"" )
//lstIds.add("${currentId}" )
}
vars.putObject("lstIds",lstIds)
You can access the list with vars.getObject("lstIds")
List of strings could be seen in the view result tree.
Another quick solution
Add a JSR223 Post Processor below the JSON Extractor to create strings with the available values.
String booksIds_ALL=vars.get("booksIds_ALL")
def lstIds = "\"" + booksIds_ALL.replace(",", "\",\"") + "\""
vars.putObject("lstIds",lstIds)
I am working on a POST service that give JSON response.
I have to extract certain value from the JSON response. example-
`{
"Result":
{ "Id":22
"StartTime":
"EndTime":
"RoutePoints":
[{ "Id":675,
}
{ "Id":676,
}
]
}
} `
My first part of the question-
How do I refer the "Id" variable inside the "RoutePoint" array using regular expression extractor? I can simply use "Id", but I also have an "Id" variable outside the "RoutePoint" array.
Secondly-
How do I take the "Id" each time and run them in a loop in the following service? Example- I take "Id=675" and perform a job, then take "Id=676" and perform that same job. Please be as detailed as possible, I am new to JMeter.
I would recommend going for JSON Path PostProcessor which is available since JMeter 3.0
Add JSON Path PostProcessor as a child of the request which returns above JSON and configure it as follows:
Variable Names: anything meaningful, i.e. Id
JSON Path Expressions: $..RoutePoints.*.Id
Match Numbers: -1
You should get variables like:
Id_1=675
Id_2=676
Id_matchNr=2
suitable for iteration with i.e. ForEach Controller
Demo:
References:
JSONPath - XPath for JSON
Advanced Usage of the JSON Path Extractor in JMeter