Help with a JS transformation

Hi all,

I am a NOOB (but learning) and I have an issue, that I'm sure it will take 2 seconds for a seasoned Retool user.

I have the following answer from my user endpoint...

{
  "Id": 1,
  "Nombre": "Irimar",
  "Apellido": "Acosta",
  "Tipo de documento": "Pasaporte",
  "Numero de documento": "234234234234sdfsf",
  "Celular": 65503337,
  "Email": "di3@gmail.com",
  "Fecha de entrada": "2022-07-01",
  "Fecha de salida": "2022-07-31",
  "Contrato firmado": 1,
  "Reviews": 4,
  "Foto": "[{\"url\":\"http://104.333.333.172:8080/download/noco/lavanda_admin/Cleaners/Foto/P3iHJj.png\",\"title\":\"cleaners.png\",\"mimetype\":\"image/png\",\"size\":6066}]",
  "Carnet de vacunacion": 1,
  "Banco": "Banco Nacional de Panama",
  "Tipo de cuenta": "Corriente",
  "Numero  de cuenta": "3534534545",
  "Nombre en la cuenta": "juan cordero",
  "Status": null
}

I am trying to use the Foto Url to fetch the profile pic, but I am struggling. Any help apreciated.

Hey @PODoingItsBest, welcome to the community.

There might be better way of solving this but here's what I came up with for that:

var test = {
  "Id": 1,
  "Nombre": "Irimar",
  "Apellido": "Acosta",
  "Tipo de documento": "Pasaporte",
  "Numero de documento": "234234234234sdfsf",
  "Celular": 65503337,
  "Email": "di3@gmail.com",
  "Fecha de entrada": "2022-07-01",
  "Fecha de salida": "2022-07-31",
  "Contrato firmado": 1,
  "Reviews": 4,
  "Foto": "[{\"url\":\"http://104.333.333.172:8080/download/noco/lavanda_admin/Cleaners/Foto/P3iHJj.png\",\"title\":\"cleaners.png\",\"mimetype\":\"image/png\",\"size\":6066}]",
  "Carnet de vacunacion": 1,
  "Banco": "Banco Nacional de Panama",
  "Tipo de cuenta": "Corriente",
  "Numero  de cuenta": "3534534545",
  "Nombre en la cuenta": "juan cordero",
  "Status": null
}

return Papa.parse(test.Foto.replace("[{", '').replace("}]",'')).data[0][0].substring(6)

Hi @PODoingItsBest

it looks like the Foto value is a stringified Array.
Convert it and access it as regular Array:

const res = {
  "Id": 1,
  "Nombre": "Irimar",
  ....
}

const Foto = JSON.parse(res.Foto)
const firstFoto = Foto[0]
const url = firstFoto.url

Hope this help

1 Like

Thanks for the help! Great community