I've been digging through Jade documentation and google searches but nothing words. I'm attempting to print a JSON string with a view but no matter how I try to print the variable, the double quotes are always converted to "
Update: I'm using Jade 0.26.0.
My test json:
{test:"value"}
My template code:
!{JSON.stringify(json)}
Raw output in the web browser:
{"test":"value"}
If you just want to pretty print an object and not export it as valid JSON you can use console. dir() . It uses syntax-highlighting, smart indentation, removes quotes from keys and just makes the output as pretty as it gets.
Use JSON. stringify(obj) method to convert JavaScript objects into strings and display it. Use JSON. stringify(obj, replacer, space) method to convert JavaScript objects into strings in pretty format.
js is a JavaScript runtime built on Chrome's V8 JavaScript engine. With node. js as backend, the developer can maintain a single codebase for an entire application in javaScript. JSON on the other hand, stands for JavaScript Object Notation.
JSON exists as a string — useful when you want to transmit data across a network. It needs to be converted to a native JavaScript object when you want to access the data. This is not a big issue — JavaScript provides a global JSON object that has methods available for converting between the two.
Maybe upgrade to more recent version of Jade?
I'm using version 0.25.0 and..
This is escaped
=JSON.stringify(item)
These are unescaped
!{JSON.stringify(item)}
!=JSON.stringify(item)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With