title: PHP convert JSON object to string
body: <p>I am making a quiz script. I want a "teacher" to be able to edit the questions. Originally, I tried to use mySQL but it was a bit difficult, so I decided to switch to a JSON file. </p>
  
  <p>After doing some basic checks with PHP, I wrote this block of code</p>
  
  <pre><code>$json = array();
  for ($x=1; $x &lt; $count + 1; $x++) { 
      $q_and_a = array(
          "Question" =&gt; $_POST["q".$x],
          "Answer" =&gt; $_POST["a".$x]
          );
      array_push($json, $q_and_a);    
  }
  $encoded_array = json_encode($json);
  // Delete JSON file, create new one and push encoded array into file
  $json_file = 'questions.json';
  unlink($json_file);
  $handle = fopen($json_file, 'w') or die('Cannot open file:  '.$json_file);
  fwrite($handle, $json_string) or die('Internal Sever Error');
  </code></pre>
  
  <p>After I got an internal server error, I realized that this is because the <code>$json</code> variable is an array; I need to convert it into a string and then insert it into the file. I first used <code>serialize()</code> but that just inserted some weird stuff into my file. How do I convert the json array into a string before moving it into the file? </p>
  
  <p>Thanks In Advance</p>