doberkofler / PLSQL-JSON

The JSON encode/decode library for Oracle PL/SQL
MIT License
47 stars 15 forks source link

How to read an array #9

Closed niden closed 7 years ago

niden commented 7 years ago

I am trying to read a node from an existing json_object with no success.

DECLARE
  indata        varchar2(2000);
  outdata       varchar2(2000);
  payloadObject json_object;
  jsonObject    json_object;
  resultObject  json_object;
BEGIN  
  indata := '{"payload":[{"value":113,"text":"AAA"},{"value":22,"text":"BBB"}]}';
  payloadObject := json_object(indata);
  json_debug.output(payloadObject);

 -- up to here great! The code below does not work

  jsonObject := json_object(payloadObject.get('payload'));
  json_debug.output(jsonObject);
END;

So the payload node contains a json_array. If I try to use the get on the object and assign it to a json_object variable, clearly it doesn't work. Changing the type to json_array again does not work .

How can I get the array stored into the payload node of my original object?

fb-datax commented 7 years ago

payload is an array not an object:

set serveroutput on size unlimited;
DECLARE
  indata        varchar2(2000);
  outdata       varchar2(2000);
  payloadObject json_object;
  jsonArray    json_array;
  resultObject  json_object;
BEGIN  
  indata := '{"payload":[{"value":113,"text":"AAA"},{"value":22,"text":"BBB"}]}';
  payloadObject := json_object(indata);
  json_debug.output(payloadObject);

 -- up to here great! The code below does not work

  jsonArray := json_array(payloadObject.get('payload'));
  json_debug.output(jsonArray);
END;
niden commented 7 years ago

@fb-datax That worked just fine. Thank you for the pointer :)