I'm trying to make a JSONPath RegEx Match on SoapUI for the following Json Response:
{
"quantidadeItens": 5,
"registros": [
{
"identificador": 1,
"descricao": "Viagem à Disney"
},
{
"identificador": 2,
"descricao": "Carro"
},
{
"identificador": 3,
"descricao": "Smartphone novo"
},
{
"identificador": 4,
"descricao": "Casa nova"
},
{
"identificador": 5,
"descricao": "Apartamento Novo"
}
]
}
On the attached Image we can see that the JsonPath is correct, but the SoapUI is not finding the match.
I guess that the [*] is not supported on SoapUI, but I didn't find anything about it on documentation.
The expected output of your JSONPath expression would be something like:
[
1,
2,
3,
4,
5
]
This doesn't match your regex, but in any case soapUI produces [1, 2, 3, 4, 5], which the soapUI documentation says is not a JSON array but just a list of values enclosed in square brackets.
So, a regex like \[(\s?[0-9]+,?)*\s?\] will match this output:
Related
i should take a JSON value, like
{
"cnt": 5
}
and create JSON object from JSONata, like
{
"1": 1,
"2": 4,
"3": 9,
"4": 16,
"5": 25,
}
I tried to do that, but i cant join two expressions correctly.
{
"" & [1..cnt] : [1..cnt].($*$)
}
and i get as a result:
{
"[1,2,3,4,5]": [
1,
4,
9,
16,
25
]
}
Can anybody help me with this(
Try [1..cnt]{$string($): $*$}
See https://try.jsonata.org/SVapg4fzt
I am using AWS Step Functions which utilizes JSONPath for providing JSON paths. I have the following input :
{
"response": {
"isSuccess": true,
"error": "",
"body": {
"count": 2,
"fields": [
{
"fieldId": 1,
"tabId": 100,
"title": "First Name"
},
{
"fieldId": 2,
"tabId": 100,
"title": "Last Name"
}
]
}
},
"iteration": {
"totalCount": 2,
"currentCount": 0,
"step": 1
}
}
I want to query the fields array as:
$.response.body.fields[$.iteration.currentCount]
The value of currentCount is incremented by 1 as part of an iteration.
I am getting an invalid XPath exception when trying to use the above.
Can someone please advice on how to provide a dynamic property value to read array values?
As described on https://github.com/json-path/JsonPath#operators you can index an array with a number only. However, you can use a filter expression to select a specific item from the array as follows.
Assuming you have another field that denotes the index such as:
{
"index": 0,
"fieldId": 2,
"tabId": 100,
"title": "Last Name"
}
You can then do
$.response.body.fields[?(#.index==$.iteration.currentCount)]
I tried to POST a new listItem to my custom SharePoint list with Microsoft Graph. It worked well until I added one specific custom column: involvedId. This is a lookup column that allows multiple values.
Here is the return of actual valid values (shortened for readability):
"Title": "Test1",
"refNumber": "Test1",
"clientIdLookupId": "4",
"involvedId": [
{
"LookupId": 3,
"LookupValue": "3"
},
{
"LookupId": 6,
"LookupValue": "6"
},
{
"LookupId": 7,
"LookupValue": "7"
}
]
So I tried an insert with the following request body:
{
"fields": {
"Title": "I9",
"refNumber": "I9",
"clientIdLookupId": "1",
"involvedId": [
{
"LookupId": 2,
"LookupValue": "2"
},
{
"LookupId": 3,
"LookupValue": "3"
}
]
}
}
I get the return code 400 (invalidRequest).
I can't find any documentation on how to POST properly multiple values.
Can anyone help?
In an MVC controller i have below piece of code
[HttpPost]
public ActionResult One(Dictionary<Guid, int[]> groups)
{
return Json(groups);
}
What is the json structure i need to provide for it to be properly serialized into the Dictionary ?
Tried below:
{
"Key": "4e89af43-59c8-492b-b646-1185e3f8776c",
"Value": [1, 2, 3, 4, 5]
}
and
{
"groups": {
"Key": "4e89af43-59c8-492b-b646-1185e3f8776c",
"Value": [1, 2, 3, 4, 5]
}
}
If you want it to be serialized into "Dictionary", you need the following structure:
{
"Key": "Value",
"Key": "Value",
"Key": "Value"
}
In your case it will be the following object:
{
"4e89af43-59c8-492b-b646-1185e3f8776c": [1, 2, 3, 4, 5],
"4e89af43-1234-492b-b646-1185e3f8776c": [0, -1, -2],
"4e89af43-59c8-5678-b646-1185e3f8776c": [7]
}
In terms of JSON request in ASP.NET you probably will need to wrap it in a object corresponding to a variable name:
{
groups: {
"4e89af43-59c8-492b-b646-1185e3f8776c": [1, 2, 3, 4, 5],
"4e89af43-1234-492b-b646-1185e3f8776c": [0, -1, -2],
"4e89af43-59c8-5678-b646-1185e3f8776c": [7]
}
}
At least, it definitely should be so in case of Dictionary<string, int[]>.
You have a Guid as a key and I hope that ASP.NET will properly serialize Guid as a string.
Seems GUID are not meant to be serialized when inside the dictionary. Here is the error i received
So i had to change my Dictionary to below and the parameters to be sent like the next piece of code
[HttpPost]
public ActionResult One(Dictionary<string, int[]> groups)
{
return Json(groups);
}
JSON Input
{"groups":[
{
"Key": "4e89af43-59c8-492b-b646-1185e3f8776c",
"Value": [1, 2, 3, 4, 5]
}
]}
Thanks to anyone and everyone who helped
I'm building a gatling 2.1.3 scenario and I need to extract data from a json body.
Example of the body:
[
{
"objectId": "FirstFoo",
"pvrId": "413"
"type": "foo",
"name": "the first name",
"fooabilities": {
"foo1": true,
"foo2": true
},
"versions": [23, 23, 23, 23, 23, 23, 24, 23, 23],
"logo": [
{
"type": "firstlogo",
"width": 780,
"height": 490,
"url": "firstlogos/HD/{resolution}.png"
}
]
},
{
"objectId": "SecondFoo",
"pvrId": "414"
"type": "foo",
"name": "the second name",
"fooabilities": {
"foo1": true,
"foo2": false
},
"versions": [23, 23, 23, 23, 23, 23, 24, 23, 23],
"logo": [
{
"type": "secondlogo",
"width": 780,
"height": 490,
"url": "secondlogos/HD/{resolution}.png"
}
]
}
]
and I have this code trying to extract de data:
exec(
http("get object")
.get(commons.base_url_ws + "/my-resource/2.0/object/")
.headers(commons.headers_ws_session).asJSON
.check(jsonPath("$..*").findAll.saveAs("MY_RESULT"))) (1)
.exec(session => {
foreach("${MY_RESULT}", "result") { (2)
exec(session => {
val result= session("result").as[Map[String, Any]]
val objectId = result("objectId")
val version = result("version")
session.set("MY_RESULT_INFO", session("MY_RESULT_INFO").as[List[(String,Int)]] :+ Tuple2(objectId, version))
})
}
session
})
My goal is:
To extract the objectId and the 9th value from the version array.
I want it to look as Vector -> [(id1, version1),(id2, version2)] in the session to reuse later in another call to the API.
My concerns are:
(1) Is this going to create entries in the session with the complete sub objects? Because in other answers I was that is was always a map that was saved ("id" = [{...}]) and here I do not have ids.
(2) In the logs, I see that the session is loaded with a lot of data, but this foreach is never called. What could cause this ?
My experience in Scala is of a beginner - there may be issues I did not see.
I have looked into this issue: Gatling - Looping through JSON array and it is not exactly answering my case.
I found a way to do it with a regex.
.check(regex("""(?:"objectId"|"version"):"(.*?)",.*?(?:"objectId"|"version"):\[(?:.*?,){9}([0-9]*?),.*?\]""").ofType[(String, String)].findAll saveAs ("OBJECTS")))
I can then use this
foreach("${OBJECTS}", "object") {
exec(
http("Next API call")
.get(commons.base_url_ws + "/my-resource/2.0/foo/${object._1}/${object._2}")
[...]
}