polymer icon indicating copy to clipboard operation
polymer copied to clipboard

Issue with vulcanized output of serialised JSON

Open markleusink opened this issue 12 years ago • 2 comments

On this page an example is given of passing a serialised JSON object to a web component. It uses this syntax:

<roster-list persons='[{"name": "John"}, {"name": "Bob"}]'></roster-list>

That works great (if I hint the attribute as a JavaScript array), but if I 'vulcanize' the page the output is:

<roster-list persons="[{"name": "John"}, {"name": "Bob"}]"></roster-list>

and the component doesn't work anymore. If you switch the single and double quotes, the vulcanized output is correct and the web component continues to work:

<roster-list persons="[{'name': 'John'}, {'name': 'Bob'}]"></roster-list>

(although that last syntax could also cause issues if you don't hint the variable and try to JSON.parse() it yourself: that won't work unless you replace the single by double quotes again)

markleusink avatar Oct 28 '14 15:10 markleusink

Sorry about the confusion. The latter syntax is correct; HTML attributes require double quotes. Although many parsers are forgiving, vulcanize apparently isn't.

I'll make a note to correct the examples.

arthurevans avatar Oct 28 '14 17:10 arthurevans

Closing this issue due to age and the release of version 1 of Polymer - please feel free to re-open if this is incorrect.

tjsavage avatar Oct 23 '15 21:10 tjsavage