SimpleArrayUtils.fromString results JsonParseException when string contains new line escape
See original GitHub issueThe following code results JsonParseException: Unrecognized character escape ‘w’
val s = """{"{\"title\": \"hello\\nworld\"}"}"""
utils.SimpleArrayUtils.fromString[JsValue](Json.parse)(s).orNull
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
How to escape a JSON string containing newline characters ...
I tried escaping the new line character \n to \\n. It is working fine. But i am looking for any JS library which...
Read more >Adding a Newline Character To a String In Java - Xperti
Find out how to add a new line to a string in Java. ... See the examples below, here escape sequences are used...
Read more >How to erase newline character from string? - MATLAB Answers
Hello,. I am reading an xml file that contains new line (enter) character. How do I detect and erase it?
Read more >Remove Newline from Character String in R - GeeksforGeeks
In this article, we are going to see how to remove the new line from a character string in R Programming Language. Example:...
Read more >Python: Insert New Line into String - STechies
Mentioning the newline character using n will bring the cursor to the consecutive line. Example 1 print('Hello n STechies'). Output: Hello STechies. We...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
for future reference, the problem seems to be in the
PgTokenHelper.getString
method. I first tried manipulating theToken
s returned byPgTokenHelper.Tokenizer.tokenize
myself, quickly realised I needed thePgTokenHelper.grouping
as well and ended up with this :the actual unescaping is done using
commons-text
StringEscapeUtils
. MyfromString
is basically a copy paste of theSimpleArrayUtils.fromString
replacing thegetString
call with anunescapeJson
call. This seems to works ok for all kinds of escaped json text inside JSON values.I encountered this error myself. Here is a problematic json value:
This represents hello + a literal backslash + n world, NOT a newline.
When stored in a
jsonb
column this is no problem, but if it is an element of ajsonb[]
array it is incorrectly parsed as:I have included a failing test case on my branch here: https://github.com/zgrannan/slick-pg/commit/4543de1b9a7c63836a048a59598255e66a0d8405
FYI as a workaround, one can change their db’s
jsonb[]
column to ajson
column and convert the data usingarray_to_json