diff --git a/docs/about/release-notes.md b/docs/about/release-notes.md
index f8e00b48..94abf6c3 100644
--- a/docs/about/release-notes.md
+++ b/docs/about/release-notes.md
@@ -19,6 +19,7 @@ You can determine your currently installed version using `mkdocs --version`:
`mkdocs build` and `mkdocs serve` (#832)
* Fixed issues with Unicode filenames under Windows and Python 2. (#833)
* Improved the styling of in-line code in the MkDocs theme. (#718)
+* Bugfix: convert variables to JSON when being passed to JavaScript (#850)
## Version 0.15.3 (2016-02-18)
diff --git a/mkdocs/commands/build.py b/mkdocs/commands/build.py
index 614173dc..04192f50 100644
--- a/mkdocs/commands/build.py
+++ b/mkdocs/commands/build.py
@@ -11,6 +11,7 @@ import jinja2
import json
from mkdocs import nav, search, utils
+from mkdocs.utils import filters
from mkdocs.relative_path_ext import RelativePathExtension
import mkdocs
@@ -228,6 +229,7 @@ def build_pages(config, dump_json=False):
site_navigation = nav.SiteNavigation(config['pages'], config['use_directory_urls'])
loader = jinja2.FileSystemLoader(config['theme_dir'] + [config['mkdocs_templates'], ])
env = jinja2.Environment(loader=loader)
+ env.filters['tojson'] = filters.tojson
search_index = search.SearchIndex()
build_template('404.html', env, config, site_navigation)
diff --git a/mkdocs/themes/readthedocs/base.html b/mkdocs/themes/readthedocs/base.html
index b19a1c89..87c9f8ab 100644
--- a/mkdocs/themes/readthedocs/base.html
+++ b/mkdocs/themes/readthedocs/base.html
@@ -27,9 +27,9 @@
{% if current_page %}
{% endif %}
diff --git a/mkdocs/utils/filters.py b/mkdocs/utils/filters.py
new file mode 100644
index 00000000..4a26c8d1
--- /dev/null
+++ b/mkdocs/utils/filters.py
@@ -0,0 +1,6 @@
+import json
+import jinja2
+
+
+def tojson(obj, **kwargs):
+ return jinja2.Markup(json.dumps(obj, **kwargs))