Google Merchant Center's structured data documentation advises adding structured data to the HTML source and not generating it post-page load using JavaScript. This doesn't mean Google can't process JavaScript-generated structured data, but it complicates the process. Jarno van Driel highlighted this on LinkedIn, questioning the discrepancy between Google Search Central and Google Merchant Center documentation.
Ryan Levering from Google clarified that both documents are technically correct, but the wording needs adjustment. He advised against re-implementing websites if they currently work, noting that Google Merchant Center crawlers can process JavaScript-generated data but often encounter quality and inconsistency issues. For example, discrepancies can arise when prices are updated via JavaScript after the initial HTML load.
Levering explained that the recommendation to avoid JavaScript for structured data in Google Merchant Center documentation was to ensure consistency across systems. However, he acknowledged that it's not entirely accurate to say JavaScript should never be used for structured data.
In summary, while JavaScript can be used for structured data, it is generally more reliable to include it in the original HTML source to avoid potential issues.