Copy link to clipboard
Copied
Hello,
So I need to generate a big number of images from 1 image (like lottery tickets) that come from a set of numbers I have in a JSON file.
I have everything working, I just can't get the script to properly work with the JSON itself... For example, if I just run this code:
Read this, which quotes the manual Script Alert - Title - Alert Box
alert is NOT a data formatter or a data dumper. It simply displays a string. So your non-string object is converted by normal JavaScript rules to a string object like "[object Object]".
In both alerts use at end:
.toSource()
Copy link to clipboard
Copied
Where is the script code we have no idea what the object in your alert messages are or how you are trying to use them. The data array seem to be missing the ; after the ]. The
alert
(uppgifter).
alert
(data[
0
]);
look strange and uppgifter is unknown to me.
Copy link to clipboard
Copied
Read this, which quotes the manual Script Alert - Title - Alert Box
alert is NOT a data formatter or a data dumper. It simply displays a string. So your non-string object is converted by normal JavaScript rules to a string object like "[object Object]".
Copy link to clipboard
Copied
Oh no, I'm guilty of that... data dumping to "inspect"!
Using Visual Studio Code ExtendScript Debugger, what is the alternative to using alert, something for the terminal/output tab?
var layLen = app.activeDocument.layers.length;
alert(layLen);
Obviously console.log(layLen); works in a browser, but not in Photoshop...
Copy link to clipboard
Copied
In both alerts use at end:
.toSource()
Copy link to clipboard
Copied
Thanks I knew of this in different contexts... So:
var layLen = app.activeDocument.layers.length;
alert(layLen);
Returns:
2
While:
var layLen = app.activeDocument.layers.length;
alert(layLen.toSource());
Returns:
(new Number(2))
Copy link to clipboard
Copied
Yes, "toSource()" and "toString()" and "eval" are your friends. You can also dump data into a text file and inspect that, which has the added advantage of giving you a de facto log file.
Copy link to clipboard
Copied
You mean 'uneval' as alternative for 'toSource()', but surely not '.toString()' 😉
Copy link to clipboard
Copied
If you are using alerts, the input is a string. Extendscript usually converts it ok but sometimes it fails miserably. Of course there is no way to tell when its going to work. LOL
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks for the help guys, indeed the problem was I was expecting it to work like a string!
Copy link to clipboard
Copied
I am in uncharted territory, the following summary is my take from the discussion and minor research around the edges.
I believe that if the data source is a separate external JSON file, then it can be parsed and treated as a standard JS object, where you can easily retrieve the properties as one would, similar to a standard DOM object.
If the JSON data is "inline" in the JS code, it could be handled as a string with JS text string/regular expressions (not an object).
I'm not sure if it is possible to convert a variable with a string of JSON "code" into a JS object as is possible with an external file.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more