title: Generate structured data with JavaScript
body: <p>We need to write a script to create a JSON-LD script for structured Data for a Component in JSP let say FAQ component, we have written script to generate JSON LD for Structured data,</p>
  <p>faq.jsp :</p>
  <pre><code>&lt;script type=&quot;application/ld+json&quot;&gt;
  {
      &quot;@context&quot;: &quot;https://schema.org&quot;,
      &quot;type&quot;: &quot;FAQPage&quot;,
      &quot;mainEntity&quot;: [
      &lt;c:forEach var='questionItem' items='${faq.faqQuestionList}' varStatus='itemsLoopSchema'&gt;
      {
      &lt;c:set var=&quot;trimmedAnswer&quot; value=&quot;${fn:trim(questionItem.answer)}&quot; /&gt;
      &quot;@type&quot;: &quot;Question&quot;,
      &quot;name&quot;: &quot;${questionItem.question}&quot;,
      &quot;acceptedAnswer&quot;: {
      &quot;@type&quot;: &quot;Answer&quot;,
      &quot;text&quot;: &quot;${fn:escapeXml(trimmedAnswer)}&quot;
      }
      &lt;c:choose&gt;
          &lt;c:when test=&quot;${itemsLoopSchema.last}&quot;&gt;
              }
          &lt;/c:when&gt;
          &lt;c:otherwise&gt;
              },
          &lt;/c:otherwise&gt;
      &lt;/c:choose&gt;
  &lt;/c:forEach&gt;
      ]
  }
  &lt;/script&gt;
  </code></pre>
  <p>Now when this JSP Component included Multiple time the script will run multiple time and create multiple JSON</p>
  <p>Instead I want to load all the multiple FAQ component and then create JSON (or run script only once).
  A single JSON LD where all the details will be there for multiple faq.jsp</p>
  <p>*Restricting Script to run once and get the data of all the page DOM in JSON for SEO purpose in JSP</p>