0
New Here
,
/t5/after-effects-discussions/how-to-read-a-local-json-file-using-cep/td-p/12389432
Sep 17, 2021
Sep 17, 2021
Copy link to clipboard
Copied
my json content : { "name": "JA"}
var path = "my Json path";
var result = window.cep.fs.readFile(path);
cs.evalScript('alert(' + result.data + ')'); // object
cs.evalScript('alert(' + result.data.name + ')'); // undefined
cs.evalScript('alert(' + JSON.stringify(result.data)+ ')'); // { "name": "JA"}
cs.evalScript('alert(' + JSON.stringify(result.data).name+ ')'); // undefined
How can i get the "name" info : JA.
Thanks for your help !
TOPICS
Scripting
,
SDK
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
2 Correct answers
Community Expert
,
Sep 20, 2021
Sep 20, 2021
JSON.stringify(result.data)
produces a string and hence
JSON.stringify(result.data).name
tries to access a property "name" of that string, which does not exist.
You probably want this (where the stringify effectively puts quotes around the name and adds any necessary escapes)
cs.evalScript('alert(' + JSON.stringify(result.data.name)+ ')');
Community Expert
,
Sep 22, 2021
Sep 22, 2021
You want to parse the data, not stringify. It's already a string when you read it.
const cs = new CSInterface();
const dataStr = cep.fs.readFile('C:/path/to/file.json').data;
const dataObj = JSON.parse(dataStr);
const name = dataObj.name;
cs.evalScript('alert("' + name + '")');
Community Expert
,
/t5/after-effects-discussions/how-to-read-a-local-json-file-using-cep/m-p/12392977#M181430
Sep 20, 2021
Sep 20, 2021
Copy link to clipboard
Copied
JSON.stringify(result.data)
produces a string and hence
JSON.stringify(result.data).name
tries to access a property "name" of that string, which does not exist.
You probably want this (where the stringify effectively puts quotes around the name and adds any necessary escapes)
cs.evalScript('alert(' + JSON.stringify(result.data.name)+ ')');
Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
LATEST
/t5/after-effects-discussions/how-to-read-a-local-json-file-using-cep/m-p/12399049#M181622
Sep 22, 2021
Sep 22, 2021
Copy link to clipboard
Copied
You want to parse the data, not stringify. It's already a string when you read it.
const cs = new CSInterface();
const dataStr = cep.fs.readFile('C:/path/to/file.json').data;
const dataObj = JSON.parse(dataStr);
const name = dataObj.name;
cs.evalScript('alert("' + name + '")');
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

