Loading JSON from InDesign javascript

I would like to load and eval a file containing JSON. Can that be done from InDesign scripting?

Yes, there is a class File and the eval() function also works.

Similar Messages

  • Loading data from a JavaScript file

    I am writing a Java application that will run client-side, and will essentially allow the user to download, update, and then reupload a JavaScript file. The data I'm needing to parse / build to the JS file consists of staticlly-defined string arrays, and one associative array.
    The file looks like this.
    var array1 = new Array();
    array1[0] = "String1";
    array1[1] = "String 2";
    array1[2] = "String 3";I'm wondering if there is a more simple/eleoquent way of loading arrays from a JavaScript file than simply reading them and writing parse code by hand to extract the data I want... I can write the parsing code without any problem, but, I'm wondering if there's something built-in that I just don't know about...
    Thanks

    You can use the ScriptEngine provided in Java 6. Takes a little hacking, but here's how you'd do it:
    a simple javascript file:
    //test.js
    var myArray = [];
    myArray[0] = 'Something';
    myArray[1] = 'To';
    myArray[2] = 'look';
    myArray[3] = 'at';
    //ScriptTest.java
    import javax.script.*;
    import sun.org.mozilla.javascript.internal.NativeArray;
    import java.io.FileReader;
    class ScriptTest {
      public static void main(String[] argv) throws Exception {
        ScriptEngine js = new ScriptEngineManager().getEngineByName("javascript");
        FileReader script = new FileReader("test.js");
        js.eval(script);
        NativeArray array = (NativeArray)js.get("myArray");
        for(int i = 0; i < array.getLength(); i++)
          System.out.printf("Object: %s\n", array.get(i, array));
    }Now, since NativeArray is an internal class, you'll need to add rt.jar to your bootclasspath:
    javac -bootclasspath JAVA_HOME/lib/rt.jar ScriptTest.javaSee. Told you it was a hack. :-)

  • How to load images from BLOB to javascript?

    hi, Guys:
    I need to load thumbnail images from BLOB to multiple markers' infowindow in Google map . I have implemented Google map in APEX. I load the data suchas text for every marker's infowindow from Oracle database table with PL/JSON, and infowindow works fine. Could anyone give me a suggestion or example so I know how to load images to javascript?
    Thanks a lot.
    Database: Oracle 11g R2
    APEX: APEX 4.1
    Thanks.
    Sam

    lxiscas wrote:
    hi, VC:
    Thanks for your kind reply. I need to render these images out of APEX session, actually in javascript that is related to Google map markers' infowindow.
    I checked the documents of APEX_UTIL.GET_BLOB_FILE_SRC, but my impression is I need to use it in APEX instead of javascript if my understanding is correct. I already implemented a procedure with PL/SQL to load images from a BLOB column in Oracle database. But the problem is, how can I pass it to javascript code out of APEX to javascript (I could pass text or number from APEX to javascript with PL/JSON though,But I assume that still google map will be within a valid apex session? if so you should be able to use the above api.
    Basically what this api does is generates a kind of url to each blob in the database, not sure how google api's deal with this though. Why don't you give it a try?
    The other option is to make your pl/sql procedure public and then you can generate the json to include the images urls such as:
         "employees" : [{
                   "firstName" : "John",
                   "lastName" : "Doe",
                   "imgSrc" : "http://somewhere/db_schema.your_download_proc?p_file=#ID#",
                   "firstName" : "Anna",
                   "lastName" : "Smith"
                   "imgSrc" : "http://somewhere/db_schema.your_download_proc?p_file=#ID#",
                   "firstName" : "Peter",
                   "lastName" : "Jones"
                   "imgSrc" : "http://somewhere/db_schema.your_download_proc?p_file=#ID#",
    }And then you can use this new attribute to populate the images in javascript using standard img tag
    See this tutorial http://docs.oracle.com/cd/E14373_01/appdev.32/e13363/up_dn_files.htm
    I did not find any method in PL/JSON to pass image object)? So far I only found example to load images from local files to javascript.Hmm..I don't think you should load image objects.
    Vikram

  • JSON from HTML embed Javascript to AS

    Hi,
    I know how to get JSON working if loading from external file
    by using LoadVars.
    But i don't know how to get JSON from the HTML embed
    Javascript and get to work in flash?
    I have tried different ways and search at google about
    related cases but nothing found yet.
    Can somebody help me?
    that's the code that i have used:

    Thanks for the suggestion.
    Well, as near as I can tell the "do javascript" will in no way, shape or form pass info back out to Applescript from Bridge, and I need to grab the long user name from system info there.
    To be honest, I was just trying to do a nice elegant dialog box with Bridge because Illustrator CS2 didn't know Script UI and I thought since everyone has CS3 Bridge on their machines already... But I've settled for 3 Applescript dialogs instead, so the fight is over.
    1.5 days tinkering with JS. 1.5 hours recoding in AS. Whee...

  • I want to find the image tag name from Image layer name InDesign JavaScript?

    I want to find the image tag name from Image layer name InDesign JavaScript?

    Hi,
    You can use following script to fetch image tag name and the layer name on which it lie:
    var imgBox = app.activeDocument.rectangles // fetch all rectangular frames from the active document
    for(var i = 0; i< imgBox.length; i++)
      if(null != imgBox[i].associatedXMLElement )
                var b = imgBox[i]
               alert("Image tag name "+imgBox[i].associatedXMLElement.markupTag.name + "\n exist on layer " + imgBox[i].itemLayer.name)
    Hope this would help you to resolve your problem.

  • How to execute the InDesign Javascript from outside in MAC

    Hi All,
    I need to execute the InDesign Javascript from outside in MAC machine.
    Anyone can help me.
    Thanks in advance.
    Regards,
    Ramkumar

    If you just want to imitate double clicking a file, use execute() method, e.g.:
    var myJavaScriptFile = new File("~/Desktop/Test.jsx");
    myJavaScriptFile.execute();
    At the top of your .jsx file type #target indesign to make the script run in InDesign.
    And I want to add to what Harbs said in the previous post: when you use do script command, you can also send parameters and get back values. See DoScriptParameters and DoScriptReturnValues sample scripts from InDesign CS3 Guide Scripts for details.

  • Stalling a form from loading until the initial javascript arrays are loaded

    I am looking for a way to get a form to be hidden based on the onload event. I would like to call a javascript function to initially populate some select boxes based on javascript arrays, but I would like this to happen before the page loads or at least stall displaying the select boxes until they are populated.
    The way it is setup now, when the page loads, the select boxes try to load first and then the rest of the form loads. I would like to know if there is a way to load the select boxes from the javascript arrays, then have the select boxes and other form elements show up at the same time. I have tried putting a <div> around the entire form and within the javascript populate function I first use "document.formname.div_id.style.visibility=hidden" then at the end of the select box population within the function, I use "document.formname.div_id.style.visiblity=visible". I tried this and the select boxes appear blank; it is as if the populate function doesn't work at all.
    I realize this is a very long question, but I will award you Duke Dollars if you help me out!!!

    right now, I have it set up where I click on a link which is a jsp page which forwards me to the jsp page that has all the html in it. That page is where I initially try to populate the select boxes with the javscript arrays...I also have a number of javascript functions which change the contents of the select boxes based on another select box in the form. Will i have access to those "java" arrays, [instead of using the javascript arrays], that you are suggesting in the javascript code? I do need to use whatever arrays I create in javascript functions.

  • IE 11: Javascript files are not loaded correctly from cache?

    Since installing Windows 8.1, I have been experiencing issues with script loading in IE 11: When the server responds with "304 Not Modified" in response to a script request, bad things happen. Specifically, I encounter script errors that would
    normally be caused by a missing script reference or having references in the wrong order (e.g. "Unable to get property 'foo' of undefined or null reference"). Doing a force-refresh (i.e. Ctrl+F5) corrects the issue until the next page load.
    Based on what I see in the IE 11 developer tools, it looks like the scripts are loaded correctly. I can open them in the Debugger view and the content appears to be correct. Perhaps IE is just not loading them in the correct order in this scenario?
    I noticed this problem myself and then someone else (who has also recently installed Windows 8.1) informed me that it appears he is experiencing exactly the same issue on a different site.

    I'm fairly certain this issue represents a bug in IE 11. The same problem(s) do not occur in IE 9 or IE 10. The same problems occur on unrelated websites accessed from separate machines. Doing a force-refresh (Ctrl+F5) always fixes the issue.
    I took your advice about opening the console to look for error messages during page load. When loading normally (i.e. not doing a force-refresh), the console shows the following:
    HTML1300: Navigation occurred.
    File: TimeEntry
    DOM7011: The code on this page disabled back and forward caching. For more information, see: http://go.microsoft.com/fwlink/?LinkID=291337
    File: Dashboard
    SCRIPT70: Permission denied
    File: modernizr-2.5.3.js, Line: 468, Column: 9
    SCRIPT70: Permission denied
    File: jquery-ui-1.10.0.js, Line: 252, Column: 1
    SCRIPT70: Permission denied
    File: knockout-2.2.1.js, Line: 48, Column: 5
    SCRIPT5007: Unable to get property 'extend' of undefined or null reference
    File: knockout.validation.js, Line: 30, Column: 5
    When loading the page via a force-refresh, only the 'Navigation occurred.' message is displayed. It does not make sense that IE would apply a more restrictive security policy to scripts loaded from cache vs. scripts loaded directly from their original location,
    yet that appears to be what is happening.
    Post questions about html, css and scripting for website development to the IE Web Development forum.....WITH A LINK TO YOUR WEBSITE OR A MASHUP THAT SHOWS THE ISSUE...
    looks like you have a sandboxed iframe on your page.
    the first step in troubleshooting IE issues is to test in noAddons mode.
    Rob^_^

  • IDCS5-win. Error while running a script from indesign(not via estk)

    Hi all,
    After running the script from indesign, I get following error
    ASSERT '(engine->getDebugFlags() & ScScript::kExtendedErrors) == ScScript::kExtendedErrors' in ..\..\..\source\components\script\javascript\JavaScriptRunner.cpp at line 412 failed.
    ..\..\..\source\components\script\javascript\JavaScriptRunner.cpp (412)
    any idea about this?
    The script runs fine when run from ES tool kit.
    Thanks

    Hi,
    My colleague found the problem. We were using extendables library and we still haven't figured out what was actually happening, but removing it solved the problem.

  • Java - Axis2: How to get an error code / error message from the Javascript via SOAP

    Hi
    In our Java applicsation we call a Javascript in a Indesign CS Server using the following code:
    --- SNIP BEGIN ---
    // calls the remote service on the indesign server
    try {
    // create service
    ServiceStub oIndsgnSrvStub = new
    ServiceStub(sIndesignServer);
    // create service parameter
    ServiceStub.RunScriptParameters
    oIndsgnSrvRSParams = new ServiceStub.RunScriptParameters();
    // create arguments with source- and target-file for parameter
    ServiceStub.IDSPScriptArg[] oIndsgnSrvSArgs = new ServiceStub.IDSPScriptArg[2];
    oIndsgnSrvSArgs[0] = new
    ServiceStub.IDSPScriptArg();
    oIndsgnSrvSArgs[0].setName("xml-input");
    oIndsgnSrvSArgs[0].setValue(sSourceFile);
    oIndsgnSrvSArgs[1] = new
    ServiceStub.IDSPScriptArg();
    oIndsgnSrvSArgs[1].setName("output-file");
    oIndsgnSrvSArgs[1].setValue(sTargetFile);
    // define service parameter
    oIndsgnSrvRSParams.setScriptArgs(oIndsgnSrvSArgs);
    oIndsgnSrvRSParams.setScriptFile(sScriptFile);
    oIndsgnSrvRSParams.setScriptLanguage("javascript");
    oIndsgnSrvRSParams.setScriptText("");
    // create runscript
    ServiceStub.RunScript oIndsgnSrvRS = new ServiceStub.RunScript();
    // set parameter
    oIndsgnSrvRS.setRunScriptParameters(oIndsgnSrvRSParams);
    //$$$ there should be an answer returned by the InddSrvr
    // execute SOAP call
    ServiceStub.RunScriptResult oIndsgnSrvRes = oIndsgnSrvStub.RunScript(oIndsgnSrvRS);
    if(oIndsgnSrvRes.getErrorNumber() == 0) {
    oServerProdJob.setProdState(CBP_Constant.REMOTEPRODUCTIONSTATE_SUCCESS);
    bOK = true;
    } else {
    oServerProdJob.setProdState(CBP_Constant.REMOTEPRODUCTIONSTATE_FAILURE);
    bOK = false;
    //$$$ should be set, if there is something returned by inddsrvr
    //oServerProdJob.setErrorMsg(sErrorMsg);
    } catch(Exception e) {
    sError += e.getMessage() + "\n";
    bOK = false;
    --- SNIP END -----
    The problem is that we don't get the error code and/or the error message from the Javascript in oIndsgnSrvRes. The error code is always 0 if I set an Integer value as return in the Javascript. If I set a String, there is an Exception in the Java application.
    Here is the Java script we use:
    --- SNIP BEGIN ---
    main();
    main()
    var sError = "";
    var sXMLInput = "";
    var sLayoutPath = "";
    // get the SDKCodeSnippetRunner object
    var cbpAdapter = app.cbpCbpadapterObject
    if (cbpAdapter) {
    sXMLInput=app.scriptArgs.get("xml-input");
    sLayoutOutputFile=app.scriptArgs.get("output-file");
    sError = cbpAdapter.doProcess(sXMLInput, sLayoutOutputFile);
    return sError; // This give an Exception; if I return an Integer the ScriptResult is always 0
    --- SNIP END -----
    If I try this with the test application from Adobe I get the error code correctly. But in the Java application, using SOAP, I can't get the error code.
    What could be wrong?
    Any ideas?
    Thanks a lot for the support.
    Kind regards
    Hans

    user11340104 wrote:
    Hello -
    i am calling sqlplus from a bash shell script. If the sql statement generates an error, how can I return that error code (unsuccessful) back to the bash shell?
    Well, let google be your friend,
    http://www.google.co.in/search?rlz=1C1GGLS_enIN327IN327&sourceid=chrome&ie=UTF-8&q=sqlplus+error+codes
    There are many threads I guess talking about the same issue.
    HTH
    Aman....

  • Write filename somewhere in a PDF when exporting from InDesign?

    Is there a way, when exporting a PDF from InDesign, to somewhere/somehow auto-embed the filename into the resulting PDF? Doesn't need to be "visible" in the job, but needs to be accessible somehow. I'm working with a very difficult client who changes PDF names and then, months later, sends the PDF back with revisions and I have no idea which file the original PDF was created from. I know I can manually enter this information, but I'm looking for a more automated way to do this?
    Regards,
    Kristin.

    Put this script into a folder "Startup Scripts" inside your scripts folder. It auto-updates the document metadata every time you save a document. This automatically is saved in an exported PDF.
    //InxAfterSafe.jsx
    //An InDesign CS3 JavaScript
    #targetengine "session"
    //Creates a simple event listener.
    main();
    function main()
    var myEventListener1 = app.addEventListener("afterSave", setMetadata, false);
    var myEventListener2 = app.addEventListener("afterSaveAs", setMetadata, false);
    function setMetadata()
    var myFileName = app.activeDocument.name.replace(/\.indd$/i, "");
    app.activeDocument.metadataPreferences.documentTitle = myFileName;
    app.activeDocument.metadataPreferences.copyrightNotice = myFileName;
    app.activeDocument.metadataPreferences.jobName = myFileName;

  • Open a file in photoshop from indesign

    Hello,
    I been trying to open a photo from indesign to photoshop.
    I loop through the selected graphic boxes  which I get the path to the images.
    I can get the path easy enough but opening them in photoshop is another matter. I been reading about Bridgetalk, but can't seem to figureout how to get bridgetalk to load the images into photoshop.
    using CS3
    code:
    if (app.documents.length != 0){
        if (app.activeWindow.activeSpread.pageItems.length != 0){
         for (i = app.selection.length-1; i >= 0 ; i--) {
             try{ 
             if(app.selection[i].graphics.length != 0)
                          var  myGraphic =   app.selection[i].graphics.item(0) ;              
                          var myLink = myGraphic.itemLink;
                          var myLinkName = myLink.name;
                          var myLinkFile = File(myLink.filePath);
                          var bt = new BridgeTalk.launch("photoshop");
                       } //end if                
        catch(err)
        } //end for loop
        }//end first if
        else {
            alert("The active spread does not contain any page items.");
    }// end second if
    else{
        alert("No documents are open. Please open a document and try again.");

    You can find an example of how to do this here.
    Kas

  • Exporting files from InDesign to correct size

    Hi,
    Hope someone can help. I create multiple ads for many publications and have joboptions set up for each. Brill, saves loads of time!
    However, some require the ad to be cropped to bleed size but still include crop marks. How can I export a PDF to the correct size (trimmed to the bleed size with crop marks but without the white space you always get?!). For instance, can you specify the length of the crop marks to make them shorter or just specify the correct trimmed size without the white space?
    At the moment I have to specify a bleed of 10mm when exporting from InDesign and then crop 7mm off all round to leave 3mm of bleed in Acrobat with the crop marks (albeit small) remaining on the document.
    The ads are delivered via adsend so if they don't pass the specs, they are automatically rejected (gone are the days when someone REAL checked them over – sigh!)
    Please, please, has anyone got a solution?!!
    I'm using CS5 and Acrobat 9 Pro.
    Oh, and I can't seem to print a postscript file or PDF anymore since we got a new crappy printer!

    You cannot export from Pages to ID, though you could export to RTF and use File > Place... to import the thext, but you'd need to rebuild the layout.
    Placed PDF is essentially a graphic, so your pixelation may just be the default preview quality. Try View > Display Performance > High Quality Display (and you can set this as the default in the prefs). Keep in mind, though, that the imported PDF is not editable in ID.

  • Using Acrobat Object in InDesign Javascript Script

    Hi there,
    for a current job, I would like to replace pages in a PDF document right after I have exported the pages from InDesign. The export works well, but now I need to instantiate an acrobat object in my InDesign Script. At the moment, I only have Photoshop and Bridge objects available in my ExtendScript IDE. Is there any way to instantiate a Acrobat object in InDesign Script?
    I use InDesign CS3 and Acrobat 8 on a Macintosh computer.
    Any help would be great!
    Thanks a lot in advance!
    Greetings
    Mimi

    I do not believe this can be entirely done from within JavaScript. You could use doScript to call a script in a different language that is capable of interacting with Acrobat.
    Dave

  • The difference of pdf export from Indesign CS3 and other Indesign version

    Hi,
    When I am exporting pdf of an Illustrator eps file from Indesign CS2 or CS4 etc.. i am getting the proper output as its there in illustrator, but when I am loading the same Image in CS3 and exporting pdf its not producing the proper output. Here I have my screen shots.
    Cs3
    other versions
    awaiting your reply
    Thanks in advance
    Biju Mathew.

    You have to educate your customer: EPS is an outdated and lossy file type because it does neither support transparency nor color management and should be avoided to be used with InDesign or Photoshop or Illustrator.
    I don't understand, why so many insist in using EPS?

Maybe you are looking for