Help

The Community will be temporarily unavailable starting on Friday February 28. We’ll be back as soon as we can! To learn more, check out our Announcements blog post.

Syntax error

693 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Jamie_Rood
6 - Interface Innovator
6 - Interface Innovator

I have a JSON array in a field called 'Output' in a table called 'Assessmnt converter'. 

I am trying to create new records into a table called 'Submissions test' and populate the data into four respective fields; Question number raw, Question raw, Number of marks raw and Student answer raw. 

I have created an automation whereby if the 'Output is not empty', it runs the following script. 

However, every time I run the script, I'm getting the following error:

CONSOLE.ERROR

  1. "Error parsing JSON data:"
  1. â–¶Error {name: "SyntaxError"}

Here is my script:

// Load the Airtable scripting environment
let assessmentTable = base.getTable("Assessment converter");
let submissionsTable = base.getTable("Submissions test");
let query = await assessmentTable.selectRecordsAsync();
let fieldName = "Output";

// Iterate over all records in the "Assessment converter" table
for (let record of query.records) {
// Get the JSON data from the 'Output' field
let output = record.getCellValue(fieldName);

// Debugging: Log the output to check its content
console.log("Output:", output);

try {
// Parse the JSON data
let jsonData = JSON.parse(output);

// Debugging: Log the parsed JSON data
console.log("Parsed JSON data:", jsonData);

// Iterate over the parsed JSON data
for (let item of jsonData) {
// Prepare the data for the 'Submissions test' table
let submissionData = {
"Question number raw": item["question number"] || "",
"Question raw": item["question"] || "",
"Marks for question raw": item["marks for question"] || "",
"Student answer raw": item["student answer"] || ""
};

// Debugging: Log the submission data
console.log("Submission data:", submissionData);

// Create a new record in the 'Submissions test' table
await submissionsTable.createRecordAsync(submissionData);
}
} catch (e) {
console.error("Error parsing JSON data:", e);
}
}
I've tried to troubleshoot this multiple times but can't seem to figure out what the issue is. Assistance would be greatly appreciated. Thanks
1 Reply 1

If you could provide a read-only invite link to a duplicated copy of your base with some example data, including example JSON that's causing the error, I could take a look at this for you!