on 2023 Aug 25 4:57 AM
I was starting on a function to replace characters that json needs to be escaped. But sybase is to clever and replaces \\n back into line break 😞
The function: ALTER FUNCTION "DBA"."JsonEnc"(IN str LONG VARCHAR ) RETURNS LONG VARCHAR DETERMINISTIC BEGIN return replace(str,char(10),'\\n') END
Test query: select 'aaa' || char(10) || 'bbb' as str, jsonenc(str) as jsonstr, replace(str,char(10),'\\n') as test
Result: str | jsonstr | test aaa aaa aaa\\nbbb bbb bbb
If the funtion replaces with say: |n it works as expected.
How do I get the function to not turn \\n back to line break.
Or is there a simpler way to escape a json string?
Request clarification before answering.
Bah, return replace(str,char(10),'\\\\n')
Needs to escape the \\
Not sure why the replace in the query does not need to escape the \\
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
41 | |
15 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.