{"id":18758715,"date":"2025-12-17T01:12:24","date_gmt":"2025-12-17T01:12:24","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/multiple-application-json-blocks-confuse-javascript-code\/"},"modified":"2025-12-17T01:12:24","modified_gmt":"2025-12-17T01:12:24","slug":"multiple-application-json-blocks-confuse-javascript-code","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/multiple-application-json-blocks-confuse-javascript-code\/","title":{"rendered":"Multiple application\/json blocks confuse javascript code"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When multiple widgets with calendar (or widget and the calendar itself) are used on a page (two same widgets for desktop\/mobile responsive design, for example), each creates its own <code>&lt;script data-js=\"tribe-events-view-data\" type=\"application\/json\"&gt;<\/code> block, while the script is not able to deal with the array of the repeating JSONs breaking JSON.parse with an error (all JSONs from the blocks concatenated into one string):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>t.setup = function(n) {<br \/>    const i = e(n);<br \/>    if (!i.is(t.selectors.container))<br \/>        return;<br \/>    const s = i.find(t.selectors.dataScript);<br \/>    let a = {};<br \/>    s.length &amp;&amp; (a = JSON.parse(s.text().trim())),<br \/>    t.initTasks(i, a)<br \/>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The easiest solution is to assume that <code>s<\/code> can have more than a single element and verify that the same data was not already parsed before.<\/p>\n","protected":false},"template":"","class_list":["post-18758715","topic","type-topic","status-publish","hentry","topic-tag-json"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18758715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18758715\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18758715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}