Quick backstory- I am building a Java web app using MVC structure and Spring Framework. My controller object calls a Python script that queries a bunch of APIs and returns a JSON payload that I would like to capture and work with in my Java file.
After aggregating information from a few different sources, here is what I have so far:
String currQuery = "cmd /c python ../../../../python/state/main.py";
Process p = Runtime.getRuntime().exec(currQuery);
p.waitFor();
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
As you can see this would print each line of the return value the script. However, what I want is to be able to interact with the JSON object returned by main.py within my Java class.
What is the best way to pass a JSON object between the python file being executed and my Java class?
Perhaps using JSONReader? Any advice/ suggestions would be greatly appreciated and let me know if more information is needed.