Using JSON files in Macros

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Using JSON files in Macros

Kirmse, Robert
Dear ImageJ List,
I have a question regarding the use of JSON files.

I would like to use a JSON file for storing settings/parameter for a macro.
However I am not sure how to use the variable in the actual macro once I read it.

So the way I tried to set it up is the following


javascript file that reads the JSON with.

...
function read JSON() {
var settings = JSON.parse(IJ.openAsString("pathToFile\\inputs.json"));
"some more code"
return(settings)
}

--------------------
and then my actual IJM file
"some code"

javacode = File.openAsString("pathToFile\\JSON_Read2.js");
settings= eval("script",javacode);


that only give the message "object array" in the log file, when I try to access settings.
I tried storing the retrieved JSON content in different variables that i tried to return but was not successfull.

I am wondering if there is an elegant way to actually get the JSON content and make them
available for the imageJ macro.

Thank you in advance for any hints

Best
Rob

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Using JSON files in Macros

ctrueden
Hi Rob,

Have you considered using a full-featured scripting language such as
JavaScript, Groovy, etc.? Then you would not have to work around
limitations of the ImageJ macro language. For details, see this page:

     https://imagej.net/Scripting

> I would like to use a JSON file for storing settings/parameter for a
> macro.

It could also help move the discussion forward if you can describe _why_
you want to do this. What are you trying to accomplish?

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Tue, Aug 22, 2017 at 2:00 AM, Kirmse, Robert <[hidden email]>
wrote:

> Dear ImageJ List,
> I have a question regarding the use of JSON files.
>
> I would like to use a JSON file for storing settings/parameter for a macro.
> However I am not sure how to use the variable in the actual macro once I
> read it.
>
> So the way I tried to set it up is the following
>
>
> javascript file that reads the JSON with.
>
> ...
> function read JSON() {
> var settings = JSON.parse(IJ.openAsString("pathToFile\\inputs.json"));
> "some more code"
> return(settings)
> }
>
> --------------------
> and then my actual IJM file
> "some code"
>
> javacode = File.openAsString("pathToFile\\JSON_Read2.js");
> settings= eval("script",javacode);
>
>
> that only give the message "object array" in the log file, when I try to
> access settings.
> I tried storing the retrieved JSON content in different variables that i
> tried to return but was not successfull.
>
> I am wondering if there is an elegant way to actually get the JSON content
> and make them
> available for the imageJ macro.
>
> Thank you in advance for any hints
>
> Best
> Rob
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Using JSON files in Macros

Kirmse, Robert
Hi Curtis
Thank yes I have considered this and for new projects I will definitely do this.

However I was also using existing macros that I would like to avoid re-implementing in another scripting language.

As to the why - the macros I am using are supposed to run in a batch/headless mode and the input parameters are supplied
through JSON files. This is in a broader environment that is why the json files are a fixed parameter at this point.

Thanks
Best
Rob

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Curtis Rueden
Sent: Mittwoch, 23. August 2017 05:08
To: [hidden email]
Subject: Re: Using JSON files in Macros

Hi Rob,

Have you considered using a full-featured scripting language such as JavaScript, Groovy, etc.? Then you would not have to work around limitations of the ImageJ macro language. For details, see this page:

     https://imagej.net/Scripting

> I would like to use a JSON file for storing settings/parameter for a
> macro.

It could also help move the discussion forward if you can describe _why_ you want to do this. What are you trying to accomplish?

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden Did you know ImageJ has a forum? http://forum.imagej.net/


On Tue, Aug 22, 2017 at 2:00 AM, Kirmse, Robert <[hidden email]>
wrote:

> Dear ImageJ List,
> I have a question regarding the use of JSON files.
>
> I would like to use a JSON file for storing settings/parameter for a macro.
> However I am not sure how to use the variable in the actual macro once
> I read it.
>
> So the way I tried to set it up is the following
>
>
> javascript file that reads the JSON with.
>
> ...
> function read JSON() {
> var settings = JSON.parse(IJ.openAsString("pathToFile\\inputs.json"));
> "some more code"
> return(settings)
> }
>
> --------------------
> and then my actual IJM file
> "some code"
>
> javacode = File.openAsString("pathToFile\\JSON_Read2.js");
> settings= eval("script",javacode);
>
>
> that only give the message "object array" in the log file, when I try
> to access settings.
> I tried storing the retrieved JSON content in different variables that
> i tried to return but was not successfull.
>
> I am wondering if there is an elegant way to actually get the JSON
> content and make them available for the imageJ macro.
>
> Thank you in advance for any hints
>
> Best
> Rob
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html