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

Posted on 2014-08-17
Last Modified: 2014-08-27
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.

Question by:deve_thomos
    LVL 76

    Accepted Solution

    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:

        \u four-hex-digits
    LVL 16

    Expert Comment

    by:Swadhin Ray
    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.

    Author Comment

    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
    return replace(replace(replace(replace(replace(replace(replace(p_column_id, '\', '\\'), '"','\"'),
    end rep;

    Open in new window

    LVL 76

    Expert Comment

    by:slightwv (䄆 Netminder)
    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?

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Introduction A previously published article on Experts Exchange ("Joins in Oracle", makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
    Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
    This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
    This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now