Have you ever wanted to use multilines strings in JSON objects ?
JSON5 allows that and much more
You can test it here : JSON5-TEST
<script src="https://unpkg.com/json5@^2.0.0/dist/index.min.js"></script>
<script>
const mscripts = {
hello : `
function hello() {
alert('hello from JSON5')
};
hello();
`
}
let str = JSON5.stringify(mscripts)
let res = JSON5.parse(str)
eval(mscripts.hello)
</script>
Top comments (3)
Hm, not sure if the tiny number of "advantages" of JSON5 justify breaking compatibility with a gazillion existing software programs and components which expect the 'classical' JSON standard. Only for a very narrow set of use cases maybe.
Hy,
Thanks for your post.
I don't think the purpose is to replace standard JSON.
It's another tool in your toolbox
Regards
For sure :-)