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

Iterate JSON Object in Premiere.jsx using JSON2.js

Explorer ,
Aug 11, 2020 Aug 11, 2020

Hello fellow extendscript coders. 

 

I am using the json2.js library as advised here: 

https://community.adobe.com/t5/animate/json-parsing-issue-object-object/td-p/9868114?page=1

 

I have a question regarding json2.js integration into Premiere.jsx I have a function

 

 

var seqObj = {

	items:{

		"1be20ac4-6d42-46be-91e3-896e9f3ae3c3":{
			end: {seconds: 8.47513333333334, ticks: 2152819468800},
			fps: 59.9400599400599,
			inPoint: {seconds: 0, ticks: 0},
			mediaPath:"",
			name: "MVI_1599.MP4",
			numTracks: 5,
			outPoint: {seconds: 8.47513333333334, ticks: 2152819468800},
			shaky: false,
			start: {seconds: 0, ticks: 0},
			trackIndex: 0,
			uuid: "1be20ac4-6d42-46be-91e3-896e9f3ae3c3"
		},
		"c0dbc73f-8e7a-4f32-bc73-bfbf6478d1a0":{
			end: {seconds: 73.02295, ticks: "18548997667200"},
			fps: 29.97002997003,
			inPoint: {seconds: 0, ticks: "0"},
			mediaPath: "",
			name: "DJI_0116.MOV",
			numTracks: 5,
			outPoint: {seconds: 55.2885666666667, ticks: "14044180550400"},
			start: {seconds: 17.7343833333333, ticks: "4504817116800"},
			trackIndex: 1,
			uuid: "c0dbc73f-8e7a-4f32-bc73-bfbf6478d1a0"
		}
		
	}

}


createSequenceFromPreset: function (presetPath, seqObj) {
	app.enableQE();

	seqObj = JSON.parse(seqObj)

        return seqData[Object.keys(seqData)[0]]

}​

 

 

 
im just trying to access the first index of the seqObj in Premiere.jsx file
 
seqObj[Object.keys(seqObj)[0]] this causes evalScript error
 
but it works in normal files where I have access to the full JSON library I think Premiere.jsx doesnt understand the Object prototype because its using json2.js

Is there any way of iterating through this JSON Object? 
TOPICS
Error or problem , SDK
495
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

correct answers 1 Correct answer

Explorer , Aug 11, 2020 Aug 11, 2020

I found the solution here:

 

https://community.adobe.com/t5/photoshop/parsing-json-in-jsx-referenceerror-object-keys-is-not-a-function/m-p/8610669?page=1

 

 

I literally had to define the Object.keys function. 

 

This feels like an obsolete and primitive solution but its the only thing I found that worked. 


 

if (!Object.keys) {

			Object.keys = (function () {
			
				'use strict';
			
				var hasOwnProperty = Object.prototype.hasOwnProperty,
			
					hasDontEnumBug = !({toString: null}).propertyIsEnume
...
Translate
Explorer ,
Aug 11, 2020 Aug 11, 2020
LATEST

I found the solution here:

 

https://community.adobe.com/t5/photoshop/parsing-json-in-jsx-referenceerror-object-keys-is-not-a-fun...

 

 

I literally had to define the Object.keys function. 

 

This feels like an obsolete and primitive solution but its the only thing I found that worked. 


 

if (!Object.keys) {

			Object.keys = (function () {
			
				'use strict';
			
				var hasOwnProperty = Object.prototype.hasOwnProperty,
			
					hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
			
					dontEnums = [
			
					'toString',
			
					'toLocaleString',
			
					'valueOf',
			
					'hasOwnProperty',
			
					'isPrototypeOf',
			
					'propertyIsEnumerable',
			
					'constructor'
			
					],
			
					dontEnumsLength = dontEnums.length;
			
				return function (obj) {
			
				if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
			
					throw new TypeError('Object.keys called on non-object');
			
				}
			
				var result = [], prop, i;
			
				for (prop in obj) {
			
					if (hasOwnProperty.call(obj, prop)) {
			
					result.push(prop);
			
					}
			
				}
			
				if (hasDontEnumBug) {
			
					for (i = 0; i < dontEnumsLength; i++) {
			
					if (hasOwnProperty.call(obj, dontEnums)) {
			
						result.push(dontEnums);
			
					}
			
					}
			
				}
			
				return result;
			
				};
			
			}());
			
		}

 

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