title: Sending a JSON encoded PHP variable to JS
body: <p>I am trying to send a PHP variable to my javascript.  In order to do this, I encode the php variable with json, send it to my view with my controller, use it as a value in a hidden html form, and then pull the value with js, using parseJSON to get the final product.  </p>
  
  <p><strong>HTML</strong> (I'm using laravel, the brackets are equivalent to php tags):</p>
  
  <pre><code>&lt;input type="hidden" id="js-helper-artist-likes" name="js-helper-artist-likes" value="{{$artist_likes}}"&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>var artist_likes = $('#js-helper-artist-likes').val();
      console.log(artist_likes);
  </code></pre>
  
  <p>In the page source, I see that the value is populating with the json string, but when I print it to the console from my js like the above, all that is showing is: <code>[{</code></p>
  
  <p>I am not sure why this is.  </p>
  
  <p>I want to perform:</p>
  
  <pre><code>var artist_likes_decoded = $.parseJSON(artist_likes);
  </code></pre>
  
  <p>to get the decoded variable in JS, but this is impossible without the encoded string coming up correctly in the artist_likes variable in js.  </p>
  
  <p>Any ideas what I'm doing wrong?  Thank you.  </p>