title: PHP - How to update JSON data in a txt file?
body: <p>Here is a JSON data example saved in a file <code>data.txt</code></p>
  
  <pre><code>   [
       {"name":"yekky"},
       {"name":"mussie"},
       {"name":"jessecasicas"}
       ...// many rows
      ]
  </code></pre>
  
  <p>I would like to update the file so it will look like this:</p>
  
  <pre><code>[
   {"name":"yekky","num":"1"},
   {"name":"mussie","num":"2"},
   {"name":"jessecasicas","num":"3"}
   ...// many rows
  ]
  </code></pre>
  
  <p>This is what I have got so far:</p>
  
  <pre><code>$json_data = file_get_contents('data.txt');
  // What goes here?
  </code></pre>
  
  <p>And how do I count how many rows there are in the JSON tree?</p>