Python Dictionary Conversion in Script Snap

Hello,

I am trying to run a python script in the script snap that mocks up some test data for unit testing pipelines. The script relies on python data types such as list and dictionary to iterate through the incoming JSON document and manipulate it.

However, the document coming in are of type java.util.LinkedHashMap. When trying to convert to a python dict using dict(in_doc), it doesn’t process the document into a dict correctly.

Initial googling returned a number of jython bug around this issue. Is there any workaround for this that I can implement?

You can see the script here: https://github.com/jskrable/test-file-gen/blob/master/snap-file-gen.py

Thanks,
Jack

Hi Jack,

the best work around to this use json.loads and json.dumps; json.loads(in_doc.get(‘str_json’)). use a mapper with JSON.stringify() to represent JSON as string and then you can use json.loads() in the script.