3 followers Follow

Use json with Jython script

Hi There,

I have seen a few articles on this but I am not having success.  I have a jython script executing via xl-rules.   It requires me to read in some json, of couse when i said import json **it didn't resolve.    **How should I handle this?   I tried putting what I though was the standard python lib in the ext folder in a sub-directory, but it didn't work.  Any help would be great!






Bernie Bonn Answered

Please sign in to leave a comment.



Hi Bernie

>  I have a jython script executing via xl-rules.   It requires me to read in some json, of couse when i said **import json **it didn't resolve.

Could you give us some more details of which steps you're using in the rule, or could you paste the rule definition itself here? I'm asking because if the step is running on a remote server, the libraries that are available will actually depend on whichever Jython version/configuration is being invoked there. As far as I recall, XL Deploy does not ship over an "on-demand" Jython setup, but uses whichever Jython the target middleware provides.

The team will hopefully be able to provide some more details!



Andrew Phillips 0 votes

Hi Bernie,

Here's a few different options to how you can do it.

Solution 1:

  1. You can keep the external module on a standard location across all machines in regards to if your jython step runs locally or remotely.
  2. In my case, i am running it on overthere.Localhost so i downloaded simplejson library and kept it under downloads /Users/amitmohleji/Downloads/simplejson-3.6.5
  3. Now in your associated script, you can type this 

import sys


import simplejson as json


This made it work for me. For some reason, i couldn't get to work my python JSON library as it was giving me some error.

Solution 2: This is a last alternative

If in your jython script, you'll type this:

import os

print os._file_

  1. This will give you the location of your os library being used by jython.
  2. It comes out like $XLD_HOME/lib/jython-standalone-2.5.3.jar/Lib/
  3. So now you may add your module to this jython jar file inside Lib folder and restart the server
  4. This should also make it work


Amit Mohleji 0 votes

Hi guys, thank a lot for responding.  

I am attaching my xl rule.   I need to execute it locally on the XLD server so I choose a jython script step.   I put the simplejson folder in ext directory and refer to it this way(below) and it works.   Thanks again for the info!!

import simplejson as json

Is this the preferred method for adding python libraries for access in jython scripts?  

Here is the rule:

<rule name="WsdlRefresh" scope="deployed">  
                 <expression>deployed.layer7WsdlUri is not None</expression>  
                   <description expression="true">'Refresh wsdl for %s' %</description>  
                   <app expression="true">deployedApplication</app>  
Bernie Bonn 0 votes