Skip to main content
Inspiring
March 2, 2019
Question

Jsx working with object

  • March 2, 2019
  • 1 reply
  • 3837 views

Accordinf what ive read,  If you need to pass complex parameters such as objects from your panel’s JS to the host app's JSX, JSON.stringify() them first (no need to JSON.parse() them in the JSX – they arrive as objects).

 

in in jsx I have the following object.

myData

this was passed from js to jsx via evalscript(myData).

i can view it and see there’s an object with the data.

My problem is I need to run a few things on this object in example: Object.keys(myData).length should return the length but instead it does nothing. 

 

Am I missing something? 

This topic has been closed for replies.

1 reply

Loic.Aigon
Legend
March 4, 2019

Hi,

If you stringify the object in the JS layer, then it comes as string in the JSX environment. You then need to "eval" that string as an object but JSON.parse isn't available by default. So you need to use Douglas Crockford's JSON2 library : JSON-js/json2.js at master · douglascrockford/JSON-js · GitHub

Just for you know, Marc Autret​ proved this lib to have some non ExtendScript Compliant issues so you may give his implementation a try : GitHub - indiscripts/IdExtenso: ExtendScript Framework for InDesign Ninjas

OhmsGAuthor
Inspiring
March 4, 2019

Elementary question but even this has scarce info, how do I include the JSON-js script in my jsx?

I tried this:

#include (..js/json.js);

@include (..js/json.js);

Then in json js I add a test function

testMyScript() {

     alert('hello');

};

Attempting to run it from jsx doesn't work.

tomzag
Inspiring
March 4, 2019

$.evalFile(pathToJSON)

My plugins: https://plugins.pixelsucht.net/