Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to read JSON file in Premiere CEP extension?

Explorer ,
Oct 03, 2019 Oct 03, 2019

I've been working on a custom tools CEP panel for premiere at our studio. I've learned a lot about extendscript over the last year and our panel is getting pretty neat.

 

Now I want to add functionality using ecternal JSON files exported from our planner software. What I want to do is read names from the JSON file that will be used to create new sequences with those names in Premiere.

 

My problem is that I can't figure out how to read the JSON files. I've been reading about the fact that extendscript doesn't support JSON by default. Including the json2.js file (like I did in one of my After Effects scripts) doesn't seem to work in Premiere.

 

Hopefully someone can help me in the right direction, thanks!

TOPICS
How to , SDK
6.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 03, 2019 Oct 03, 2019

Can't you use the standard javascript JSON.parse()? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 03, 2019 Oct 03, 2019
No, JSON is not supported by default. But I found a solution. I'll share it here.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 03, 2019 Oct 03, 2019

I found a solution. To get some JSON functionality into premiere CEP, you need to include this json.jsx in your panel's main jsx file: https://github.com/indiscripts/extendscript/tree/master/JSON

 

In my panel's Premiere.jsx i have this code and it works perfect:

#include "json.jsx";

var jsonFile = File(pathToJSONFile);
jsonFile.open('r');
var content = jsonFile.read();
jsonFile.close();

contentObj = JSON.eval(content);

Now 'contentObj' is an object with all the data from the JSON file. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 03, 2019 Oct 03, 2019

You can just use JSON2

https://cdnjs.com/libraries/json2

and include it with

//@include 'json.js';
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 04, 2019 Oct 04, 2019
Ah, so if I understand correctly it's the way I included it with #include that didn't make it work with JSON2?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 04, 2019 Oct 04, 2019
LATEST
You can use //@include or #include, I like the former better cause it doesn't show errors in your IDE. You basically read the file with ExtendScript and then parse the contents with JSON.parse()
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines