Home > Back-end >  Replace " with double quotes json
Replace " with double quotes json

Time:11-23

I am working in webflow(a website platform) and pasting a JSON-LD script in a content field. The field is mapped to the section of the webpage.

All the double quotes " in the JSON script are getting switched to "

Is there a line of code that I can add to the script that will switch them back?

I tried inserting the following before the </script> tag .replace(/&quot;/g, '\"') and .replace(/&quot;/g, '\\"') and neither one worked.

Here's what the code looks like on the backend before publishing

<script type='application/ld json'>
{Schema}
.replace(/&quot;/g, '\\"')
</script>

And this is what it renders on the live site

<script type='application/ld json'>

{ &quot;@context&quot;: &quot;https://schema.org&quot;, &quot;@type&quot;: &quot;FAQPage&quot;, &quot;mainEntity&quot;: [{ &quot;@type&quot;: &quot;Question&quot;, &quot;name&quot;: &quot;How quickly can I get my certificate of insurance?&quot;, &quot;acceptedAnswer&quot;: { &quot;@type&quot;: &quot;Answer&quot;, &quot;text&quot;: Certificates are usually issued 24 hours after the policy is bound.&quot; } }]
}
.replace(/&quot;/g, '\\"')
</script>

CodePudding user response:

.replace needs to be attached to a string variable, so unfortunately you can't use it at the end of your Schema. The script tag is also application/ld json (not /javascript) so javascript won't be able to run inside the tag.

The core of this issue is that webflow is taking everything that you're entering into the block, treating it to be web safe text, and then publishing it, so a fix inside the script tag will run before that happens (and then be overridden).

So it looks like an issue with the content block that you're using. Are you able to move from a standard text block to a Rich Text Format block, or a block specifically for code?

It looks like some people are having a similar issue in this webflow support thread

Good luck!

CodePudding user response:

  1. First you missed " before Certificates word in the json object
  2. you can not run js function into script of type application/ld json
  3. Check this example of removing " from the JSON

<script type='application/ld json'>

{ 
  &quot;@context&quot;: &quot;https://schema.org&quot;, 
  &quot;@type&quot;: &quot;FAQPage&quot;, 
  &quot;mainEntity&quot;: 
  [
    { 
      &quot;@type&quot;: &quot;Question&quot;, 
      &quot;name&quot;: &quot;How quickly can I get my certificate of insurance?&quot;,
      &quot;acceptedAnswer&quot;:
      {
        &quot;@type&quot;: &quot;Answer&quot;, 
        &quot;text&quot;: &quot;Certificates are usually issued 24 hours after the policy is bound.&quot;
      } 
    }
  ]
}
</script>
<script>
var jsonld = document.querySelector('script[type="application/ld json"]').innerText;
jsonld = jsonld.replaceAll("&quot;", '"');
jsonld = JSON.parse(jsonld);
console.log(jsonld);
</script>

  • Related