Skip to content
Advertisement

Export a Json object to a text File

I’m trying to write a Json object (JsonExport) and I’d like to write its content into a text file.

I’m using max4live to export data from Audio DAW to Json in order to export to a server, but after that I would like to see the whole Json Object in a text file:

 var txtFile = "test.txt";
 var file = new File(txtFile);
 var str = JSON.stringify(JsonExport);


 file.open("write"); // open file with write access
 file.write(str);
 file.close();

The compiler runs with no error, but i can not get the text file. I have used as well path to some of my directories and nothing.

Any idea what’s happening? Thanks

Advertisement

Answer

Finally I got it! It worked by changing few parameters like this:

   var txtFile = "/tmp/test.txt";
   var file = new File(txtFile,"write");
   var str = JSON.stringify(JsonExport);

   log("opening file...");
   file.open(); 
   log("writing file..");
   file.writeline(str);
   file.close();

Path to my directories not allowed, so i had to save it on /tmp directory. Thanks to all!

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement