Thanks Moe,
It was great help for me.
I did some change in your javascript function for rule 2 and rather than returning value of individual field, I am returning json object and mapping the response field, which is working fine for all the field except company, position, duration and technical skills as they are the arrays.
These four field are capturing only first record of each arrays in the Tadabase table.
Here is the Modified function:
function extractValueFromJson(jsonString) {
let jsonObject = jsonString;
// Check if the input is a string and parse only if necessary
if (typeof jsonString === âstringâ) {
try {
jsonObject = JSON.parse(jsonString);
} catch (error) {
console.error(âInvalid JSON string:â, error);
return null;
}
}
return jsonObject;
}
const jsonString = {myChatGPTResponse};
extractValueFromJson(jsonString);
Response I am getting as following:
{
âstatusâ: âsuccessâ,
âresultâ: {
ânameâ: âJohn Doeâ,
âemailâ: âjohndoe@email.comâ,
âphone numberâ: â(123) 456-7890â,
âdegreeâ: âBachelor of Science in Computer Engineeringâ,
âinstitutionâ: âUniversity of Techâ,
âgraduation yearâ: â2016â,
âcompanyâ: [
âXYZ Corpâ,
âABC Technologiesâ
],
âpositionâ: [
âIT Systems Engineerâ,
âSoftware Engineerâ
],
âdurationâ: [
âJune 2020 - Presentâ,
âJan 2017 - May 2020â
],
âtechnical skillsâ: [
âProgramming Languages: Python, Java, C++â,
âFrameworks: Django, Flask, Reactâ,
âDatabases: MySQL, PostgreSQL, MongoDBâ,
âCloud Technologies: AWS, Azureâ,
âVersion Control: Git, GitHub, GitLabâ,
âTools: Docker, Kubernetes, Jenkinsâ
],
âlanguagesâ: âN/Aâ
},
âexpressionâ: âfunction extractValueFromJson(jsonString) {\n let jsonObject = jsonString;\n\n // Check if the input is a string and parse only if necessary\n if (typeof jsonString === âstringâ) {\n try {\n jsonObject = JSON.parse(jsonString);\n } catch (error) {\n console.error(âInvalid JSON string:â, error);\n return null;\n }\n }\n\n return jsonObject;\n}\n\nconst jsonString = { "name": "John Doe", "email": "johndoe@email.com", "phone number": "(123) 456-7890", "degree": "Bachelor of Science in Computer Engineering", "institution": "University of Tech", "graduation year": "2016", "company": ["XYZ Corp", "ABC Technologies"], "position": ["IT Systems Engineer", "Software Engineer"], "duration": ["June 2020 - Present", "Jan 2017 - May 2020"], "technical skills": ["Programming Languages: Python, Java, C++", "Frameworks: Django, Flask, React", "Databases: MySQL, PostgreSQL, MongoDB", "Cloud Technologies: AWS, Azure", "Version Control: Git, GitHub, GitLab", "Tools: Docker, Kubernetes, Jenkins"], "languages": "N/A" };\n\nextractValueFromJson(jsonString);â
}
Response mapping is as following:
Now, I removed the .0 from the following field to get the array items. It worked.
Thanks,
Khalid