Hey,
I am trying to fetch a value inside a JSON structure and I cannot get it right. Maybe this community can give me a hint how to write my smart value variables for this use case
Background: I have read up a bunch of Assets objects via the Assets REST API end point: /object/aql. The webResponse is an array of objects under the "values" tag.
I create a branch from the {{webResponse.body.values}} smart value and call the branch variable myObject. So far so good. In each object structure in the array there is an attributes-array called attributes. In this array I need to get the value for an attribute with a specific attribute-id.
The structure looks like this (simplified):
{
"values": [
{
"id": "20",
"attributes": [
{
"objectTypeAttributeId": "4839",
"objectAttributeValues": [
{
"displayValue": "Some attribute value"
}
]
},
{
"objectTypeAttributeId": "4853",
"objectAttributeValues": [
{
"displayValue": "This is my value to fetch"
}
]
}
]
},
{
"id": "21",
--- the next object ---
In my branch I create a variable to get the attribute array:
varAttributes --> {{myObject.attributes}}
This works fine. But I can't get down to the requested attribute-id from here. I would like to create a variable that gives me the value "This is my value to fetch", i.e. the value from the attribute with ID "4853".
I have tried a number of variants of setting a new variable to something like: {{#varAttributes}}{{.}}{{/}} and some if-clause that tests for the ID value, but I can't get it right.
EDIT Oct, 1st:
I am still struggling with this and I am now approaching it using @Bill Sheboy solution with Dynamic list searching using a regular expression. The issue I am facing now is that I can't iterate over the field-array: attributes.
I have my variable varAttributes as described, but it does not seem to be a list I can iterate over and use dot-notation. This is what I need to do
{{#varAttributes}}{{objectTypeAttributeId}}:{{.}}~~{{/}}
But it seems it is not a list that I can iterate like this. Is it possible to "convert" it to such a list?
Looking forward to hear back from you!
Cheers,
// Svante
Hi @Svante Gustafsson Björkegren
Perhaps the nested structure is recognized as text rather than as an object.
You could test that by using jsonStringToObject() on your branch variable, and then trying to access each attribute:
Kind regards,
Bill
Hi @Svante Gustafsson Björkegren
What if you would simply do: {{webResponse.body.values.attributes.objectTypeAttributeId}}
Do you get all the ID's then?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, that will give me the attribute-ids but I need to fetch another field in the structure where the id=4853
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.