Help with some xml parsing

Hi All, hope you can help me.

I'm trying to get some data via an api, this is working ok and i'm getting a response.

The call i'm making is search for contacts , so its returning a list of contacts based on surnames.

here is the json response i am seeing

its returning 5 key results, effectively i probably want to user Firstname and lastname in retool mobile as a list of items that the user can then select and get more detail on. so id want to display the detail for each key in the list

The issue i'm having is using the data im getting back in a clean way. I've tried a few guides but i cant quite get it right

i've looked at this

Formatting GET API responses - App Building - Retool Forum
and this

[Retool Blog] Building a Custom Amazon EC2 Instance Admin Panel for DevOps - Retool Tips & Tricks - Retool Forum

this one seems really close to what i'm trying to achieve but i struggle when trying to ge tthe fields out , i think its probably because it doesnt like the a: in the response
here is the transformer i have tried

image

on line 9 i just cant seem to get any deeper into the fields after data[key]

hopefully i'm making sense, any help would be appreciated

anyone ?

Hey Devon thanks for including a screenshot of your data structure. It looks like your data is an array of json objects whose members are arrays. Something like this

const data = [{
"a:field1": ['value1'],
"a:LastName": ['value2']
}, {
"a:FirstName":['value3']
}];

Let's say you want value3 from the above structure. You could get it in two ways:

// Directly reference the value if you know where it sits within your data
let lastName, firstName = undefined;const firstObject = data[0];
lastName = firstObject["a:LastName"][0];const secondObject = data[1];
firstName = secondObject["a:FirstName"][0];

Directly referencing is a good choice if you know the structure of your data will be the same for every user, and you only need two known values. However, if you want a more general solution see the following:

// Programmatically search your data for the value
let lastName, firstName = undefined;

// For each object in the top-level array
data.forEach((o) => {
// If the key you're looking for exists on the object
if (o.hasOwnProperty('a:FirstName')) {
// Store the value of the object
firstName = obj['a:FirstName'][0];
} else if (o.hasOwnProperty('a:LastName')) {
lastName = obj['a:LastName'][0];
}
});

Let me know if this works for you, or if you have follow up questions.

1 Like

thanks for the reply was useful , if anything it showed me how to get the a:Lastname into my exisintg query and get it worklng!