How to observe an object property with numeric key, as:
"employees":[
{"1": 0, "2":"John", "3":"Doe"},
{"1": 1, "2":"Anna", "3":"Smith"},
]
Observing whole object works well with: employees.*
But can not target specific property as: employees["2"] .
How can specific property be targeted?
Here is Plunk example.
To observe all changes to the 2nd employee in your example, you'd use Deep sub-property changes on array items:
observers: [
'bigup(datatable.employees.#1.*)'
],
plunker
In order to have observer on deep property you can mention that property in observer datatable.employees.2. You can read more on it here.
I've also updated plunkr
for you
Related
I'm working on power automate and I have an issue because I've tried a lot expressions and none of them working.
I did a loop (foreach) and inside a message (compose) and there I tried to display "f7626790-0756-43bf-a757-a645a33b853d" from"client"
To do so, I've tried all those expressions:
item()?['client']
item()?['client']?[0]
item()['client']
Here my json file:
[
{
"gift": [
{
"client": "f7626790-0756-43bf-a757-a645a33b853d",
"details": [
{
"client_id": 10859085,
"type": "christmas",
"application_id": "6e6d758d-8e74-3ae3-ac84-50eb23ae65f"
}
]
}
]
}
]
Thank's in advance.
Based on the JSON you provided, you have two arrays. So the question for me is, which array do you want to iterate? Both or the inner one?
I'm going to assume both or if not, it won't matter if you only ever have one item for both of them, my answer will still retrieve the client property.
The Initialize Data step has your JSON.
The Initialize Client step is a blank string at this stage.
The For Each Outer Item expression is simply a link to the Data variable as initialized in the first step.
The For Each Gift expression is set as ... item()?['gift'] ... as you can work out, that will loop over each gift item.
Finally, I get the value of the client property using this expression ... item()['client']
Is it possible to get the parent object from a child object dynamically? Essentially, all I'm trying to accomplish is to dynamically retrieve the value of a property belonging to a child objects' parent. For example, in the following Json, I want to extract the driver of a particular car.:
{
"driver": [
{
"id": 1, |
"name": "Bob", |=> this is the parent
"age": "34", |
"car": [
{
"make": "BMW", |
"model": "3.20", | this is the child
"colour": "Silver",|
"mileage": [
{
"total": "350523",
"year": [
{
"2011": "3535",
"2012": "7852",
"2013": "8045"
}
],
"month": [
{
"december": "966",
"november": "546",
"october": "7657"
}
]
}
]
}
]
}
]
}
Using for loops:
for(let parent of data.driver) {
for(let car of parent.car) {
if(car.make === 'BMW') {
// can do what you like with 'parent'
}
}
}
Using filter() or find() (standard javascript):
drivers_who_drive_bwm = data.driver.filter((parent) => {
// find() will give -1, if no car was found that matched
// car.make === 'BWM'
return parent['car'].find((car) => car.make === 'BWM') !== -1
})
Also:
Your naming conventions are confusing. I would expect driver.car to be a single car, in your code it's array of cars. If it always contains single car, then it would be better not to use array. Same for .driver. Better key would be .drivers to indicate multiple drivers. (but maybe it is XML converted to json, in that case you are stuck with it?)
Whatever strategy you choose, you will basically be iterating through and returning. So I feel the "best" strategy is using what you are most comfortable with.
Typescript is just Javascript. So if you are comfortable with a Javascript-ey "functional programming" way of doing things you can use Array map & filter.
You of course will have to deal with application specific logic you have not specified like "What happens when the same make/model exists across different drivers?".
If you are not comfortable with functional programming you can always build up a series of maps and then perform lookups.
But if you need to get it right, always do what you are comfortable doing.
To answer this question, an Object reference is just a memory location. there is no concept of parents comes here. its may not have any parent (just a logical thinking as parent, so may not any other object have property having reference to it), or may a lot of object have referred to same memory location (i.e. multiple parent by your logic).
1> So Either you can put parent reference to each child element programitically. Note, here you cannot do by parsing a JSON string, because its contains only JSON data, not reference as parse-able.
2> Or else Try to find out the driver object (i.e. parent object) having child object which contains your value according to your condition. you ca use filter , map of array functions in javascript to do so. but whatever you are doing is just iterating and find. in that case underscrore js will be a good library to use
Testing a rest service in SoapUI, I need to do a property transfer from a testcase response to a request in different test case.
JsonResponse in the first testcase is as follows:
{[{
"items":[{
"id": "1234",
"state": "XYZ",
"type" : "ABCD"
},
{
"id": "12345",
"state": "XYZV",
"type" : "ABCDF"
}
]}
The id(just one) from the response has to be directed to the Json request of the second testcase via property transfer
{
workItemsId: ["1234"],
field: "ABCD"
}
I have tried using items[0].id, but that transfers only the value. I need it as an array in the response. Any help would be deeply appreciated. I am so new to SOAP-UI.
IMO the easy way to do so is using the property expansion. For you case you can use the follow notation approach ${Test step name#Response#JSONPath}.
Supposing you have a first testStep named REST Test Request with the follow response:
{
"items":[
{"id": "1234","state": "XYZ","type" : "ABCD"},
{"id": "12345","state": "XYZV","type" : "ABCDF"}
]
}
And you want to use the first id from items array in a second testStep request and setting it inside array you can use the follow notation:
{
workItemsId: [${REST Test Request#Response#$items[0].id}],
field: "ABCD"
}
UPDATE
If as you comment you want to use the JSONPath expression in a property transfer, add a Property transfer testStep, select as source your request, as property response, as path language JSONPath then put the expression $items[0].id and finally select the property where you want to put the result. Finally your property transfer will looks like:
Hope it helps,
Are you using two test cases for this or just two test steps?
Anyways, rather than transferring the property directly to next request, you can set it as a property on test case and then use that property in next request with property expansion.
So,
create a property "id" on test case.
In property transfer step set the value of this property using items[0].id
In next request use property expansion to populate the value, so json will look like:
{
workItemsId:["${#TestCase#id}"],
field: "ABCD"
}
Here are more details about property expansion : https://www.soapui.org/scripting---properties/property-expansion.html
Using extractions api in keen.io I can't get back specific properties that are objects.
curl "https://api.keen.io/3.0/projects/PROJECT_ID/queries/extraction?api_key=READ_KEY&event_collection=COLLECTION_NAME&timeframe=this_7_days"
Gives me back all properties, let's say
{"result": [
{
"userId": 1,
"keen": {"timestamp": 'val', "created_at": 'val'},
"name":'val'
}
]}
But if I want to get just "userId" and "keen", the "keen" gets ignored.
curl "https://api.keen.io/3.0/projects/PROJECT_ID/queries/extraction?api_key=READ_KEY&event_collection=COLLECTION_NAME&timeframe=this_7_days&property_names=["userId","keen"]"
{"result": [{"userId": 1}...]}
I also noticed that I can get back specific properties from keen object if I specify:
property_names=["userId", "keen.timestamp"]
Result
{"result": [
{
"userId":"1",
"keen":{"timestamp":"val"}
}
]}
But I would like to get the whole object without specifying all properties. I have a top level property that is an object with many properties.
After contacting keen.io (very responsive and informative) I confirmed that retrieving just specified object with all its properties is not implemented at the moment and the only solution for now is to either get all of them or specify each property in the request (like i did in question above).
They will discuss adding this feature as it makes sense to have it working like that.
I have an anonymous array in JSON returned from a service like:
[
{"foo":1, "bar":2 , "baz":3 },
{"foo":3, "bar":4 , "baz":5 }
]
How can I access the bar elements e.g. in
expect().body("$[*].bar", hasItems(2,4))
I tried a few possibilities that I found here and also on the JsonPath page by Stefan Gössner, but whatever I try I get exceptions. My issue seems to directly come from trying to access that list of items.
Given that you have:
[
{"foo":1, "bar":2 , "baz":3 },
{"foo":3, "bar":4 , "baz":5 }
]
You can do the following in Rest Assured:
then().body("bar",hasItems(2,4))
or
expect().body("bar",hasItems(2,4))
if you're using the legacy API.
Johan's answer is correct, just for the sake of completeness: An alternative way to check the 'bar' elements with rest-assured would be
expect().
body("[0].bar", equalTo(2)).
body("[1].bar", equalTo(4));