Menu

Put large array into Json object

2013-05-14
2013-05-28
  • Eddy Rakhman

    Eddy Rakhman - 2013-05-14

    Hi,

    I'm new to PL/JSON an currently I'm facing trouble to make a JSON object like this :

    {
      "record" : [{
        "number" : 1,
        "name" : "name 1",
        "address" : "address 1"
      }, {
        "number" : 2,
        "name" : "name 2",
        "address" : "address 2"
      }, {
        "number" : 3,
        "name" : "name 3",
        "address" : "address 3"
      }]
    }

    To get the above result, my PL/SQL is like this :

    declare
        jObj json;
        jArray json_list;
        jElm json;
        n number := 3;
    begin
        jObj := json();
        jArray := json_list();
        jElm := json();
        for i in 1..n loop
            jElm.put('number',i);
            jElm.put('name','name '||i);
            jElm.put('address','address '||i);
            -
            -
            - etc
            jArray.append(jElm.to_json_value);
        end loop;
        jObj.put('record',jArray);
        jObj.print;
    end;

    As the 'n' number increase, say 30000, the process slows down, so slow that it similar to not working process. I've tried to debug the process and it seems that the bottleneck of it reside in the jObj.put('record',jArray) line.
    Is there any other way to achieve the same result as I need?

    Thanks.

     
  • James Sumners

    James Sumners - 2013-05-14

    Come up with a better design? Seriously, that's a LOT of objects in one serialization.

     
  • Eddy Rakhman

    Eddy Rakhman - 2013-05-14

    If for this purpose I add an empty array by this line in the beginning :
    jObj.put('record',jArray);

    with the result like this :

    { "record" : [
    ]
    }

    Can I add the elements to the array later? How can it be done?

     
  • Eddy Rakhman

    Eddy Rakhman - 2013-05-15

    My actual objective is to generate a .json file containing that json object with an array that have large number of elements in it.
    Any suggestion on how to do this?

    Thanks.

     

Log in to post a comment.