Hi I’m having several problems I’m basically trying to parse a long string value that I believe is formatted as a json which isn’t working and then return a json object using a custom js module.
Before I continue its worth mentioning I’m not familiar with Json and being assisted by GPT through most of this so forgive me for any rookie mistakes.
To give some context I am taking the question and answers provided from a calendly form that someone fills upon scheduling, that is stored as a long string value in a data storage(reasons stored the array like this is for a different conversation).
Now the problems I’m having upon retrieving the long string to show you an example of is formatting first is…
[{"answer":"Redacted number","position":0,"question":"Telephone"},{"answer":"gd","position":1,"question":"Your business website (if you don't have one please type no website). "},{"answer":"$20,000 to $50,000","position":2,"question":"From your business, what is the range of your monthly income? "},{"answer":"gd","position":3,"question":"What's your monthly income goal?"},{"answer":"g","position":4,"question":"What’s the #1 biggest obstacle holding you back from hitting your revenue goal? (don’t skip this part, we need to know as much as possible to help you best)"},{"answer":"Yes, of course!","position":5,"question":"Have you got a working funnel setup?"},{"answer":"g","position":6,"question":"Have you used Facebook ads before? If so, what was your experience?"},{"answer":"Absolutely! I have the means and I'm ready to take things to the next level. ","position":7,"question":"Are you at a stage where investing in your business is a possibility? "},{"answer":"Without a doubt! I'm all in with my business, ready to invest and grow quickly.","position":8,"question":"If I were to advise a monthly ad budget of at least $500 to meet your financial goals, would you say: "},{"answer":"I recognize that if I don't have a funnel in place, there might be costs involved in repairing or constructing it, to ensure that we can direct traffic to it.","position":9,"question":"Final note: "}]
1.When I use a parse to json module I end up with 3 variables which are just parts of the first elements of the array not the entire string/array as I’d want it formatted as a json object to use in my code.
2.When I’m trying to parse it within the custom js module I keep getting the error
[500] {“error”:“Unexpected token , in JSON at position 1361”}
I also have another issue with trying a different approach without trying to convert that long string into json is with my custom cs I’m unable to return a json object and getting the error:
Validation failed for 1 parameter(s).
Missing value of required parameter ‘json’.
This is the new code I’m trying to achieve this:
let dataString = input;
function escapeRegex(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}
function getAnswer(questionText) {
let questionPattern = escapeRegex(questionText);
let regex = new RegExp('"question":"' + questionPattern + '","answer":"(.*?)"', 'i');
let match = regex.exec(dataString);
if (match && match[1]) {
return match[1];
} else {
return null;
}
}
let incomeRangeQuestion = "From your business, what is the range of your monthly income? ";
let investmentReadinessQuestion = "Are you at a stage where investing in your business is a possibility? ";
let adBudgetResponseQuestion = "If I were to advise a monthly ad budget of at least $500 to meet your financial goals, would you say: ";
let telephoneQuestion = "Telephone";
let incomeRange = getAnswer(incomeRangeQuestion);
let investmentReadiness = getAnswer(investmentReadinessQuestion);
let adBudgetResponse = getAnswer(adBudgetResponseQuestion);
let telephone = getAnswer(telephoneQuestion);
let textReminderNumber = "";
let phoneNumberUsing = textReminderNumber.trim() !== "" ? textReminderNumber.trim() : (telephone ? telephone.trim() : null);
let leadQuality = "";
if (
adBudgetResponse === "No chance! That amount is just too high!" ||
adBudgetResponse === "Yes... I could stomach that. Let’s talk numbers a bit more." ||
investmentReadiness === "No way... My finances are stretched thin, and I'm at my limit."
) {
leadQuality = "Bad Lead";
} else if (
investmentReadiness === "Absolutely! I have the means and I'm ready to take things to the next level." &&
adBudgetResponse === "Without a doubt! I'm all in with my business, ready to invest and grow quickly." &&
incomeRange === "Below $10,000"
) {
leadQuality = "Good Lead";
} else if (
investmentReadiness === "Absolutely! I have the means and I'm ready to take things to the next level." &&
adBudgetResponse === "Without a doubt! I'm all in with my business, ready to invest and grow quickly." &&
incomeRange !== "Below $10,000"
) {
leadQuality = "Very Good Lead";
} else {
leadQuality = "Unqualified";
}
output = {
leadQuality: leadQuality,
phoneNumberUsing: phoneNumberUsing
};