The lightbringer The lightbringer - 2 months ago 10x
Javascript Question

Storing long formatted text for a web app

My intention is to store books and other types of large blobs of formatted text (100 to thousands of words on each chapter) to be displayed with their format in an application built with the aurelia framework. I would prefer using JSON, but I could try other alternatives. The text has been written using google docs.

So far, trying to use JSON, Visual Studio Code says

Unexpected end of string
at the first carriage return, and the application gives me an error in the console:

Unhandled rejection SyntaxError: Unexpected token in JSON at position 780

Is there any way to indicate to JSON that something is formatted text, or any decent alternative?


You're JSON has characters in it that aren't properly escaped. Most likely these are quote " characters and need \" before them all. Unless you have a particularly robust workflow setup to handle this, you're going to run into this problem a lot with large documents, especially coming from a word processor.

Instead, why not simply store the material as HTML? It is specifically designed to store and markup documents. It has headings, paragraphs, lists, etc. Browsers are already equipped to display it without doing any processing and it can be easily injected into your application by simply appending it to any element on the page.

Additionally, Google Docs should be able to save the document as HTML directly, so you don't have to do any manual markup.