Parsing a JSON string

Naresh
2012-05-16
2013-05-28
  • Naresh
    Naresh
    2012-05-16

    Hi,
       I am new to JSON. I would like to parse a given JSON string and insert the data into the Database. Are there any examples ?

    Thanks

    Naresh

     
  • James Sumners
    James Sumners
    2012-05-16

    Here's a small example that parses a JSON string. The given JSON string is a representation of an object that has two properties: one with a string value and a second with an array value.

    declare
      str       varchar2(255) := '{"foo":"bar","nums":[1,2,3,4]}';
      json_obj  json;
      json_lst  json_list;
    begin
      json_obj := json(str); -- convert the JSON string to an object
      json_lst := json_list(json_obj.get('nums'));
      
      dbms_output.put_line('foo = ' || json_obj.get('foo').to_char);
      
      for i in 1..json_lst.count
      loop
        dbms_output.put_line( json_value.get_number(json_lst.get(i)) );
      end loop;
    end;
    /
    
     
  • Naresh
    Naresh
    2012-05-17

    Thanks. That was really simple.

     
  • James Sumners
    James Sumners
    2012-05-17

    No problem. Glad it helped.

     
  • Dave S
    Dave S
    2013-01-22

    Yeah, thanks for this.  Helped me too.