1

I needed to load external file to my app. type of json. I am needed to read html content like this(the html will be the value):

<div style="font-size:16px; color:red; text-align:center; display:flex">
  <h1 style="some-style">some text</h1>
  <p style="some-style">some text</p>
  <p style="some-style">some text</p>
  <p style="some-style">some text</p>
  <footer style="some-style">some copyrights!</footer> 
</div>

from json like this:

{
"email": {
 "subject": "User registered!",
 "html": {here goes the html block}
  }
}

Every-time I am writing html in json is very difficult to writing because the double quotes. How can if fix it and can writing a right html? There is any generator for this or any solution?

I needed to html for the module nodemailer to send email. I want to read from json because the main idea it's to send for my clients the json file and they can to add any changes with the value and adding the json from outside after that ,as a volume via docker build.

Guy 235
  • 21
  • 2
  • 1
    Does this answer your question? [Write HTML string in JSON](https://stackoverflow.com/questions/22551586/write-html-string-in-json) – Felix G Jan 23 '22 at 17:24
  • You just need to escape the quotes. Most json serializers have an easy way of doing this. – William Rosenbloom Jan 23 '22 at 17:26
  • i dont really understand but maybe what you are looking for is [.innerHTML](https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML)? you can get the entire pages html as a string by doing `document.documentElement.innerHTML;` – KyleRifqi Jan 23 '22 at 17:26
  • Maybe consider an alternative file format instead of JSON that doesn't require escaping? For example, [YAML](https://yaml.org/) or [HOCON](https://github.com/lightbend/config/blob/master/HOCON.md). Both are backwards compatible to JSON, so a JSON file is also a valid YAML or HOCON file. (HOCON was originally written for Java, but JS/node implementations exist.) – RoToRa Jan 23 '22 at 20:49

0 Answers0