should be something like this:
if (parent.metadata != null && parent.metadata != undefined) {
  return cb(JSON.parse(parent.metadata).type);
}
else {
  ...
}