Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Trying to get array count

Alopez
2012-03-06
2013-05-28
  • Alopez
    Alopez
    2012-03-06

    Hi,

    If i use the follwing command:

       j_Obj := json(j_Array.get(i));

       inner_list := json_list(j_Obj.path('ProcessParameters'));
       inner_list.count = 1

    The inner_count of 1 is correct as i have only one ProcessParameters array.
      But i need to know how many app_item entries there are in the array?

       [{ 'id_app_pocess':'1',
           'id_cust':'44',
           'ProcessParameters': [ {'app_item':'id_company','value':'15'},
                                                   {'app_item':'id_city','value':'4'}
                                            ]
        }
      ]

    What command can i use to figure how many entries there are in the
    ProcessParameters array?

    I use PLJSOn version 1.02.

    Thank you,

    Anibal

     
  • James Sumners
    James Sumners
    2012-03-06

    How about:

    declare
      json_obj json := json('{"ProcessParameters":[{"foo":"bar"},{"bar":"baz"}]}');
      json_lst json_list;
    begin
      json_lst := json_list(json_obj.get('ProcessParameters'));
      dbms_output.put_line( json_lst.count );
    end;
    /
    
     
  • Alopez
    Alopez
    2012-03-06

    Is there way to get the ProcessParameters from the full object string below:

    [ { 'id_app_pocess':'1',
        'id_cust':'44',
       'ProcessParameters':
      }
    ]

    Thx.

    Anibal

     
  • James Sumners
    James Sumners
    2012-03-06

    What isn't clear about the example? I just skipped the step of retrieving the first object from an outer array.

     
  • Alopez
    Alopez
    2012-03-06

    Hi,

    Need the array count on the ProcessParamater so that i could loop trough.
    Now the count is 1 instead of 2.

    Thx.

    Anibal

     
  • Alopez
    Alopez
    2012-03-06

    Hi,

    I receive a clob:
    [ { 'id_app_pocess':'1', 'id_cust':'44', 'ProcessParameters':  } ]

    j_Array   := json_list(clob);
    v_Arrcnt := j_Array.count;

    I can get the values of app_item and value like this:

    v_app_item             := json_ext.get_string(json(j_Array.get(i)),'ProcessParameters.app_item');
    v_app_item_value := json_ext.get_string(json(j_Array.get(i)),'ProcessParameters.value');

    But i need the count on the ProcessParameters as this might one to many relationship so that i can loop trough.

    Thx.

    Anibal

     
  • James Sumners
    James Sumners
    2012-03-06

    Fine, I'll make the logic leap for you:

    declare
      json_lst json_list := json_list('[{"id_app_pocess":"1","id_cust":"44","ProcessParameters":[{"app_item":"id_company","value":"15"},{"app_item":"id_city","value":"4"}]}]');
      json_obj json;
    begin
      json_obj := json(json_lst.get(1));
      json_lst := json_list(json_obj.get('ProcessParameters'));
      dbms_output.put_line( json_lst.count ); -- 2
    end;
    /
    
     
  • Alopez
    Alopez
    2012-03-09

    Hi,

    Thx.

    It's working.