2

I need to convert json object to varchar using PL/JSON library. For an example,

declare
mapData     json;
text        varchar2(20)
begin

json := 'json object';
text := convert_to_varchar(json);
end;
Janitha Madushan
  • 1,453
  • 3
  • 28
  • 40

1 Answers1

3

Assuming you know that your JSON will fit into a varchar2:

text := mapData.to_char();

This method is clearly defined in the JSON type declaration -- https://github.com/pljson/pljson/blob/master/src/json.typ#L56

James Sumners
  • 14,485
  • 10
  • 59
  • 77
  • 1
    Any idea what would happen if your JSON looked like this: "Number": "0000000000" ? I'm not sure if the quotations should be there. But is there a method to get back the values within the quotes or should I do a replace on the quotes? – Sniipe Apr 29 '16 at 09:45
  • 1
    Honestly, no. If the data really came in quoted, then it should be interpreted as a string. But if value wasn't quoted, then you'd just have `0` as the parsed value. – James Sumners Apr 29 '16 at 12:46