Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 842
  • Last Modified:

How to make a generic function for json data in oracle ?

Hi expert,
on below query i am handling json. actually exactly i dont know which  special character handled by json and which one is not handled by json. so when i was entering data to this particular field , i have observed that these many characters are not supported by json , so i replaced this character like below. but exactly i donot know which is supported by json and which is not supported json. so i want a generic function , by which all special characters can handle by json.
 
   replace(replace(replace(emp_name,'\' , '\\\\' ),'''' , '\''' ),'"' , '\\"'  ) ;

Open in new window


for above things is working fine but problem is i dont know  how  many specail charecters are there like this which is not handle by  json. so i want to make a generic function with all special characters which can handle by JSON.

Regards
Thomos
0
deve_thomos
Asked:
deve_thomos
  • 2
  • 2
1 Solution
 
slightwv (䄆 Netminder) Commented:
I don't think that will work.

Those characters only need escaping in specific instances not every occurrence.

As far as the characters that need escaping, go to the source:
http://json.org/

char
    any-Unicode-character-
        except-"-or-\-or-
        control-character
    \"
    \\
    \/
    \b
    \f
    \n
    \r
    \t
    \u four-hex-digits
0
 
Swadhin RaySenior Technical Engineer Commented:
Can you check "utl_url.escape " and "utl_url.unescape"  to escape.
I am not 100% sure but this escape the URL 's but still can be used on any varchar2(4000) characters.
0
 
deve_thomosAuthor Commented:
below is my code
 I have handle for above json charecters but i am not getting idea how to handle hexadecimal digits(/U).
function rep(p_column_id  varchar2) return varchar2 as
begin
return replace(replace(replace(replace(replace(replace(replace(p_column_id, '\', '\\'), '"','\"'),
CHR(9),'\t'),CHR(8),'\b'),CHR(13),'\r'),CHR(12),'\f'),CHR(10),'\n');
end rep;

Open in new window


Regards
Thomos
0
 
slightwv (䄆 Netminder) Commented:
I don't know a lot about JSON.

I can help with the regular expression once I understand the patterns.

What do they look like in JSON?
0
 
deve_thomosAuthor Commented:
THANKS A LOT
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now