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
deve_thomosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.