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.

Lotusmeristem
  • 53
  • 3
  • 13

1 Answers1

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))
Lotusmeristem
  • 53
  • 3
  • 13