Help in converting i:nil "true"

Hi All, me again with a basic question

I'm getting a json response that is a null as shown below

image

here is the transformer i am using to get the response , how do i convert the


const data = {{GetContactDetails.data}}
      
// Initialize an empty array to hold final data
let finalData = [];
// Loop through each key in the data object

  // Retrieve specific data points for each instance and assign to variables
    let Lastname = data["a:LastName"][0];
    let Firstname = data["a:FirstName"][0];
    let Dob = moment(data["a:DateOfBirth"][0]).format('DD.MM.YYYY');
    let Contactid = data["a:ContactId"][0]  ;
 let email = data["a:EmailAddress"][0];
let landline =data["a:LandlineNumber"][0];
let Mobile =data["a:MobileNumber"][0]

  // Create a new object containing all relevant data points
  let newObj = {
     'Lastname': Lastname,
     'Firstname': Firstname,
    'Dob' : Dob,
    'ContactId': Contactid,
    'Email': email ,
    'Tel' : landline,
    'Mobile':Mobile
      };

  // Add new object to the finalData array
  finalData.push(newObj);


// Log finalData to the console and return it
console.log(finalData);
return finalData;

image

to something more descriptive , like a text field?

Since the e-mail has a nested keyed object could you use an in-line ternary operation?

  // Create a new object containing all relevant data points
  let newObj = {
     'Lastname': Lastname,
     'Firstname': Firstname,
    'Dob' : Dob,
    'ContactId': Contactid,
    'Email': Object.keys(email).includes('$') ? 'no e-mail address on file' : email,
    'Tel' : landline,
    'Mobile':Mobile
      };

can you show what FirstName or a text property looks like? it seems to be a nested object and I'm not sure if all types are this way or just email for whatever reason.

heres a generic function from StackOverflow for renaming keys

function renameKeys(obj, newKeys) {
  const keyValues = Object.keys(obj).map(key => {
    const newKey = newKeys[key] || key;
    return { [newKey]: obj[key] };
  });
  return Object.assign({}, ...keyValues);
}
/**
usage:

const obj = { a: "1", b: "2" };
const newKeys = { a: "A", c: "C" };
const renamedObj = renameKeys(obj, newKeys);
console.log(renamedObj);
**/

some changes might need to be made for your structure w nested objects, but I think you could just do renameKeys(newObj["Email"]["$"], { "i:nil": "text" }) which should rename 'i:nil' to 'text' giving you:

Email: {
  $: {
    text: "true"
  }
}