Skip to main content
Inspiring
December 29, 2023

JSON Format Support in After Effects and Potential Error on Restart

  • December 29, 2023
  • 0 replies
  • 374 views

When a script uses JSON format for configuration,
it can be executed correctly by calling the script in the Window menu after After Effects 2024 has launched.
However, if the script is docked in the workspace to automatically run when After Effects starts,
an error occur stating that JSON is undefined when After Effects is restarted.

Of course, you can include json2.js in the script to avoid this problem,
but since After Effects already supports JSON,
there is no need to take this extra step.
This is a test script that you can try out to dock in the workspace and restart After Effects yourself.

var jsonString = '{"name":"John", "age":30, "city":"New York"}';

try {
var jsonObject = JSON.parse(jsonString);
alert("JSON.parse successful! The parsed object is:\n" + JSON.stringify(jsonObject, null, 2));
} catch (e) {
alert("JSON.parse failed, error message:" + e.message);
}

var panel = (this instanceof Panel) ? this : new Window("palette", "JSON.parse Test", undefined);
panel.orientation = "column";

var button = panel.add("button", undefined, "JSON.parse");

button.onClick = function () {
alert("JSON.parse Test")
};

if (panel instanceof Window) {
panel.center();
panel.show();
} else {
panel.layout.layout(true);
}