I have a question about getting json into my jython script. Here's my scenario:
So with those limitations, I want to take a dictionary object on my laptop, turn it into json, deliver it to the hosted jython app and then use the native jython or java tools to turn it back into that dictionary object so I can continue working on it in my script hosted in the cloud.
I already know how to do this in "regular" python. It's easy. import json and go nuts. But my java kung fu is weak and I've never worked in jython before.
So I'm trying to figure out if this if it's possible to do this reliably and easily using the java underlying the jython or if I'd be better off using something like ast and just send the dictionary as a string literal. I'd honestly prefer to stick with json for all the normal reasons people like json so any help with leveraging the java libraries to do this work would be appreciated.
I forgot about this question. My core problem here was that I was using a 3rd party cloud offering and they were the owners of the Jython install so I was limited in what I could change about the Jython environment. At the time I was thinking I could leverage a JAVA library that would be available to jython to solve this problem but that never worked out.
While jython was out of my control I did control how I sent the data so instead of using JSON, I sent formatted strings and then used the python ast library, which was in jython, to turn those strings into python objects.
In the end it looked something like this:
thestring = """['name', 'quest', 'favorite color']"""
theobject = ast.literal_eval(thestring)
That type of logic let my python script on my local machine post strings to a web app running jython and convert those strings into python data types and then use them. It was exactly what I wanted to do with JSON without actually using JSON - it was python dicts so it looked an awful lot like JSON if you weren't really paying attention.
Thanks everybody for your suggestions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With