Copy link to clipboard
Copied
For example:
There are two files my.json and aa.jsx in the same path.
I have a code in my.json that looks like this:
{
"oldCode": "60068"
}
I now want to use var changeCode="10020" in aa.jsx to change the value of oldCode.
How to achieve it?
Thank you very much.
Hi @dublove have a study of this:
/**
* Example of reading, parse and writing JSON file.
*
* @author m1b
* @version 2025-06-25
* @discussion https://community.adobe.com/t5/indesign-discussions/how-to-use-js-to-modify-the-content-in-a-certain-json/m-p/15387727
*/
//@include '../../../../Lib/json3.js'
(function () {
// read the json file's contents
var myJSON = readFile('my.json');
if (!myJSON)
return alert('Could not read JSON file.');
// parse as json
myJSON ...
Copy link to clipboard
Copied
test.jsx just adds the modified oldCode code you gave me.
The rest is just a test.
Create PDF, here is just a test, I still mainly want to modify the oldCode in my.json
Copy link to clipboard
Copied
The new one, it seems, is much harder to understand and not easy to interface with other js.
It's a straight tip:
Copy link to clipboard
Copied
Hi m1b.
There should be an error in the file.
I tested file and redefined it and there was no prompt, but of course it was an error and no result.
I don't know how to correct it.
var file = new File(pathToMyJSONFile);
file.open();
file.encoding = "UTF-8";
success = file.write(bom + data);
file.close();
Copy link to clipboard
Copied
Hi m1b.
The problem seems to be solved, I didn't use this new one you posted, this one I couldn't read.
The problem is:
my.JSON path can not have Chinese characters.
And my.JSON file can not have comments, blank lines!
Copy link to clipboard
Copied
Hey @dublove
From what I read, I understand you have a script that is populated by a Json file. So far so good.
The way I'm using them, Json files are settings files that are created/ updated via .jsx files (ie scripts).
My question would then be : Is it the case here? Is your json file created by your .jsx script, or is it just reading datas from it? If so, how was the Json file created in the first place?
The usual way would be to run the script / locate the edittext where value needs to be changed / change it / save it.
From there, the json file should be update with the new value so then when you run the script the next time, it would be with the updated value.
I'm afraid I can't help more with the little information provided ^^
Copy link to clipboard
Copied
Hi Fred.L
The json is created manually.
I don't really understand it either.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more