fpluis
fpluis

Reputation: 189

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?

Upvotes: 0

Views: 370

Answers (2)

Soviut
Soviut

Reputation: 91555

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 transcribing, 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.

Upvotes: 1

yevt
yevt

Reputation: 816

You need to escape special characters. This discussion may help. Note that you will probably have your own list of escaped characters, which depends on your source string.

Upvotes: 0

Related Questions