question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

As far as I can see in liquid.js and render.js, the logic is:

function stringify(val) {
  if (typeof val === 'string') return val;
  return JSON.stringify(val);
}

This is generally ok, except for objects which have a toString() function.

As far as I understood from the MDN site, the safe test for string would be:

Object.prototype.toString.call(x) === '[object String]'

Until a fix will be available, a possible workaround is to add a getter:

  get toStr () {
    return this.toString()
  }

and in the template use it explicitly {{ object.toStr }}.


There is also a problem with JSON.stringify(), for complex objects it fails with Converting circular structure to JSON.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
harttlecommented, Aug 14, 2018

Both to_liquid and toLiquid supported, published @5.2.0

0reactions
dmalancommented, Aug 14, 2018

Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON.stringify() - JavaScript - MDN Web Docs
The JSON.stringify() method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or ...
Read more >
JSON.stringify() - W3Schools
JSON.stringify() ... A common use of JSON is to exchange data to/from a web server. When sending data to a web server, the...
Read more >
JavaScript JSON stringify() Method - GeeksforGeeks
The JSON.stringify() method in Javascript is used to create a JSON string out of it. While developing an application using JavaScript, ...
Read more >
JSON Stringify Online
JSON Stringify Online helps convert string value to JSON String using JSON.Stringify(). It's very simple and easy way to create JSON String value...
Read more >
stringify - Wiktionary
To find the first digit in a positive number, stringify it and take the first character.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found