SourceForge has been redesigned. Learn more.
Close

Need support for escaping quotes, backslashes

Anonymous
2010-03-01
2013-05-28
  • Anonymous

    Anonymous - 2010-03-01

    Need support for strings containing quote characters.

    This code fails with a JSON parse error because the quotes are not escaped.

    declare
      jc clob;
      j json := json();
    begin
      j.put('x', '"q"');
      dbms_lob.createtemporary(jc, false);
      j.to_clob(jc);
      j := json(to_char(jc));
    end;
    /

     
  • Jonas Krogsboell

    You're right. That's an error.

    The string input should be validated and possibly be corrected.

     
  • Jonas Krogsboell

    The "bug" persist in the new version - here's why:

    There's no way to know whether a varchar2 is intended to be escaped or not. But there is a way to tell if it is a valid JSON-string (version 0.9 code):

    json_parser.parse_any( '"' || str || '"' )
    

    Adding escapes to an already escaped string would cause it to be double-escaped. It is also slow to escape chars in a string (not just a search replace for " and \") and I would like the JSON impl. to be fast.

    Perhaps you could write to functions: escape and unescape that ensures proper escaping according to the control characters in the json standard.

    /Jonas

     
  • Manu

    Manu - 2010-10-19

    Hello

    i have string like 12/10/2010 and when i print de string returns 12\/10\/2010 how can i do to get 12/10/2010?

    thanks !!

     
  • Manu

    Manu - 2010-10-19

    i have change when chr(47) then buf := '\/'; by when chr(47) then buf := '/'; in json_printer.

    i don`t kwon it can take more problems but until now works.

     
  • Jonas Krogsboell

    You're right: the character solidus ( / ) does not need to be escaped. The output "12\/10\/2010" is correct but I will add an option so that you can disable escapement for solidus.

    Just out of interest: What platform is receiving our json-text?

     
  • Manu

    Manu - 2010-10-19

    I am creating a json in oracle and after i print it in a browser its something like a tree directories, its works but when i pass the lenght of varchar2 don`t work, 

    can i save it in a clob and print it all?

    Thanks !!

     
  • Jonas Krogsboell

    Yes - just use the to_clob function on json, json_list or json_value.
    You could also grab the output from dbms_output.

    /Jonas

     

Log in to post a comment.