How to pass PHP variables to Javascript/jQuery?
You'd be better off using drupal_add_js() to pass your object in the JS Drupal.settings object:

// In PHP:
drupal_add_js(array('myModule' =&gt; array('variables' =&gt; $variables)), 'setting');

// In JS
var variables = Drupal.settings.myModule.variables;


Drupal handles all the conversions of objects/arrays internally and this is just a much cleaner way of doing it...at the moment you're including raw JSON as part of the page output which isn't great in terms of semantics; also bear in mind that search engines will pick up this text even though you're hiding it for users with javascript.

I'd also recommend separating this logic out from the template file itself and put it in a template_preprocess_ function in your theme's template.php file...again it's just cleaner. e.g.

function MYTHEME_preprocess_html(&amp;$vars) {
  $variables = $your_variables;
  drupal_add_js(array('myModule' =&gt; array('variables' =&gt; $variables)), 'setting');
}


Have a look at the link to the drupal_add_js() function, there are quite a lot of options and you'll probably find them quite useful.