Saving new Lines in database and Json

java replace new line char with br
mysql separator new line
replace r n in android
replace all r n
android replace \n to br
rn use in java
rn string java
java replace r with n

I have this problem: I have an HTML textarea which is filled by the user. (And he can press The enter button to go on a new line). Then I take The value of The textarea using the command:

document.getElementById("textareaCommento")

And I pass The value to the servlet using an XmlHttpRequest. In The servlet I save this value in a database. Since this point I have no problems...

Then, in another part I want to get The values from The database. Using a servlet I make this query

Select * from comments

And I transform the results in json. Here I have The problem... The newline character makes my JSON string invalid. For example:

"Comment":"hello
Word"

How can I do? Thanks in advance!

You have to replace the \n character from database to something like <br/>

For the replace see replace \n and \r\n with <br /> in java

Line breaks ("\n") won't work with json fetched data, I would like to add line breaks \n to <Text>. I noticed that \n will work fine if passed from Javascript, but it will not when data is fetched in JSON  JSON is a viable option for transferring data between systems. It has the ability to include schema information along with the data which is an advantage over CSV files. In this article, Phil Factor demonstrates how he takes advantage of JSON when exporting or importing tables.

this CSS worked for me,

white-space: pre-line;

JSON Lines, This page describes the JSON Lines text format, also called newline-delimited JSON. JSON Lines is a convenient format for storing structured data that may be​  The DOM provides random access to data in a JSON payload. The JSON elements that compose the payload can be accessed via the JsonElement type. The JsonElement type provides array and object enumerators along with APIs to convert JSON text to common .NET types. JsonDocument exposes a RootElement property.

You should be able to url encode your values so hello world would actually become "hello%20world", to do it in java see here:

Encoding URL query parameters in Java

To do it in javascript see here:

Encode URL in JavaScript?

Storing Multi-Line Strings in JSON with JSONLint, Storing Multi-Line Strings in JSON with JSONLint our text block, we just have to join them back together on the newline characters, which we can do like this:  I have this problem: I have an HTML textarea which is filled by the user. (And he can press The enter button to go on a new line). Then I take The value of The textarea using the command: document.getElementById("textareaCommento") And I pass The value to the servlet using an XmlHttpRequest. In The servlet I save this value in a database.

Insert new line in json string, Oracle Database 12c Release 1 ushered in a new age of JSON inside Oracle Database through JSON Lines files may be saved with the file extension . In this post, we will add JSON data to Sql Server tables using ASP.NET Web API, JSON.NET and SqlBulkCopy. The data is posted using jQuery ajax to web api which accepts JObject type argument, parse data, arrange data in the required table structure and save to database. Here is the structure of JSON and SQL Server tables.

Save to Database: JSON to DB, Intermediate: 30m: Use conn:execute{} to insert new JSON messages or data from of the different types of node trees and save it to a database. Note: The newlines (\n) and 3 spaces at the start of lines 28 to 31 are only for  If your JSON documents are stored in local files, on shared network drives, or in Azure Files locations that can be accessed by SQL Server, you can use bulk import to load your JSON data into SQL Server. If your line-delimited JSON files are stored in Azure Blob storage or the Hadoop file system, you can use PolyBase to load JSON text, parse it

Newline delimited JSON is awesome - Jaga Santagostino, I needed to query the last or last (n) items quickly. The problems. Since i wanted to store JSON a JSON-like database like MongoDB was the  By default, json.dump will output just a single line, so you’re already good to go. If you want just one large list, simply read in the file with json.load, overwrite it (with myfile.truncate()), and write your new list out.

Comments
  • \n is the new line character. It is there
  • When you query the database the \n and \r chars are also returned. It is very likely that you cannot see them but surely they are there
  • really? I did not know! so before putting the string in json format I do character substitution \n with the sequence <br>?
  • yes , use the link i gave you ine my answer to replace also \r characters
  • ok, the replace works, but when i put the text in a td field of a table, it shows <br/>. it don't go on a new line...:(