0

I tried this solution, and the highest ranking solution here and none work.

I have a java automation script that I need to run a python script remotely while giving it a JSON object to treat as a dictionary.

JSON object as the java give it: {\'oracle_11gd.pcap\': \'19.0.0.10\' ,\'oracle_11g_also.pcap\': \'19.0.0.17\'}

The object is actually longer, I just gave a sample here.

The solution each fails, and I suspect it's because of the backslashes, but I can't even bring it in as a string to replace the backslash with nothing, like this:

data = str(sys.argv[1])
    data = data.replace("\\", "")

    transportDictionary = ast.literal_eval(data)

I tried just

data = sys.argv[1]

Also didn't work.

1 Answer 1

0

The solution I found was to echo the JSON into a JSON file on the remote machine where the python runs, while using sed to replace the backslashes and single quotes into nothing and double quotes. Like so:

echo {\'oracle_11gd.pcap\': \'19.0.0.10\' ,\'oracle_11g_also.pcap\': \'19.0.0.17\'} sed 's|\\||g' | sed 's|\\x27|\"|g' > pcaps.json

Then, in the python, I read the file and json.load like so:

import json

.
.
.

with open(directory + 'pcaps.json', 'r') as f:
    data = json.load(f)
    transportDictionary = eval(json.dumps(data))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.