Newbie question

2010-01-25
2013-05-28
  • Gareth Stephens

    Gareth Stephens - 2010-01-25

    Hi,

    I'm new to JSON and I'm struggling to understand PL/JSON.  I think it can help with what I'm trying to do but I'm a bit stuck at the moment.

    The background is we have an Application Express application where users have a requirement to upload CSV data and edit it before comitting the data to a proper Oracle table.  What I'd like to achieve is use the Yahoo API datatable to provide an editing interface to the users.

    As far as I see it the best way to do this is using the file upload capability of Apex is to upload the file to apex, extract the stored BLOB and convert it to a CLOB. Then iterate through each line of the CLOB and converting the string to a JSON object, once I've done this I pass this back to the Yahoo datatable as JSON and I think that should be able populate the Yahoo datatable.

    So far I can upload the file and then read through it a line at a time correct.  What I cannot work out currently is how to create the JSON.  I think I want something like:

    { "ResultSet" :
         [
           { "rownum": 1,
             "column1": "Hello",
             "column2": "World"
           },
           { "rownum": 2,
             "column1": "Goodbye",
             "column2": "World"
           }
        ]
    }
    

    Where the number of columns, column1/2 etc, can vary (i.e. I'd like it to be as generic as possible and use the first line as a header row if the user indicates it as such - the fallback is Column 1..n).

    If someone could provide an example or, better yet, and explanation then it would be much appreciated!

    Regards,

    Gareth.

     
  • Jonas Krogsboell

    you could do it something like this:

    declare
      resultset json;
      row_list json_list := json_list();
      columns json;
    begin
      for i in 1 .. num_rows loop
        columns := json();
        columns.put('rownum', i);
        for x in 1 .. columns_length loop
          column.put('column'||x, data);
        end loop;
        row_list.add_elem(columns.to_anydata);
     end loop;
     resultset := json();
     resultset.put('ResultSet', row_list);
     resultset.print;
    end;
    
     
  • Gareth Stephens

    Gareth Stephens - 2010-02-03

    Hi Jonas,

    Thanks for that - it was exactly the example I need to get me going.

    Now finding PL/JSON very useful.

    Regards,

    Gareth.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks