title: Pass JSON Data from PHP to Python Script
body: <p>I'd like to be able to pass a PHP array to a Python script, which will utilize the data to perform some tasks. I wanted to try to execute my the Python script from PHP using shell_exec() and pass the JSON data to it (which I'm completely new to).</p>
  
  <pre><code>$foods = array("pizza", "french fries");
  $result = shell_exec('python ./input.py ' . escapeshellarg(json_encode($foods)));
  echo $result;
  </code></pre>
  
  <p>The "escapeshellarg(json_encode($foods)))" function seems to hand off my array as the following to the Python script (I get this value if I 'echo' the function:</p>
  
  <pre><code>'["pizza","french fries"]'
  </code></pre>
  
  <p>Then inside the Python script:</p>
  
  <pre><code>import sys, json
  data = json.loads(sys.argv[1])
  foods = json.dumps(data)
  print(foods)
  </code></pre>
  
  <p>This prints out the following to the browser:</p>
  
  <pre><code>["pizza", "french fries"]
  </code></pre>
  
  <p>This is a plain old string, not a list. My question is, how can I best treat this data like a list, or some kind of data structure which I can iterate through with the "," as a delimiter? I don't really want to output the text to the browser, I just want to be able to break down the list into pieces and insert them into a text file on the filesystem. </p>