Skip to main content

The {{json}} helper safely serializes a value to JSON for inline output in your theme. This is especially useful when you need to pass server-rendered data into a <script type="application/json"> block or into a JavaScript-powered UI.

Example Code

The helper outputs escaped JSON that is safe to embed inline:

Passing an object

Passing named values

If you pass hash arguments, {{json}} serializes those named values instead:

Notes

  • Returns null when the input value is undefined
  • Escapes unsafe characters such as <, > and & for inline script safety
  • Intended for JSON output, not for formatting arbitrary HTML