Report Result

Click button Get JSON on right side to get data!

Example

For all examples I've used this SQL query as source for building JSON:
select rownum x
     , owner a
     , object_name b
     , object_type c 
  from all_objects
Classic Report Example
begin
  apex_util.json_from_sql(
    sqlq => 'select rownum x'||
                 ', owner  a'||
                 ', object_name b'||
                 ', object_type c'|| 
                 ',from all_objects');
end;                               
declare
  c sys_refcursor;
begin
  open c for
    select rownum x
         , owner a
         , object_name b
         , object_type c
      from all_objects;
        
  apex_json.open_object;
  apex_json.write('row', c);
  apex_json.close_all;
end;                               
declare
  v_tab typ_t_all_objects;
begin
  select rownum x
       , owner a
       , object_name b
       , object_type c 
    bulk collect
    into v_tab
    from all_objects  
   where rownum <= 500;

  apex_json.open_object;
  apex_json.open_array(p_name => 'row');
  for i in v_tab.first..v_tab.last
  loop            
    apex_json.open_object;
    apex_json.write('X', v_tab(i).X);
    apex_json.write('A', v_tab(i).A);
    apex_json.write('B', v_tab(i).B);        
    apex_json.write('C', v_tab(i).C);                
    apex_json.close_object;                         
  end loop;        
  apex_json.close_array;    
  apex_json.close_object;                 
end; 
declare
  v_cnt pls_integer := 0;
begin
  sys.htp.prn('{"row":[');
  for i IN (select rownum x
                 , owner a
                 , object_name b
                 , object_type c
              from all_objects)
  loop
    if v_cnt = 0 then
      sys.htp.prn('{"X":"' || i.x || 
                 '","A":"' || i.a || 
                 '","B":"' || i.b ||
                 '","C":"' || i.c || '"}');
    else
      sys.htp.prn(',{"X":"' || i.x || 
                  '","A":"' || i.a || 
                  '","B":"' || i.b ||
                  '","C":"' || i.c || '"}');
    end if;
    v_cnt := 1;
  end loop;
  sys.htp.prn(']}');
end;
declare
  v_cnt pls_integer := 0;
  v_tab typ_t_all_objects;
begin
  select rownum x
       , owner a
       , object_name b
       , object_type c 
    bulk collect into v_tab
    from all_objects;
  sys.htp.prn('{"row":[');
  for i in v_tab.first .. v_tab.last
  loop
    if v_cnt = 0 then
      sys.htp.prn('{"X":"' || v_tab(i).x || 
                 '","A":"' || v_tab(i).a || 
                 '","B":"' || v_tab(i).b ||
                 '","C":"' || v_tab(i).c || '"}');
    else
      sys.htp.prn(',{"X":"' || v_tab(i).x || 
                  '","A":"' || v_tab(i).a || 
                  '","B":"' || v_tab(i).b ||
                  '","C":"' || v_tab(i).c || '"}');
    end if;
    v_cnt := 1;
  end loop;
  sys.htp.prn(']}');
end;
declare
  obj json;
  obj2 json;
  obj_list json_list;
  v_tab typ_t_all_objects;
begin
  select rownum x
       , owner a
       , object_name b
       , object_type c 
    bulk collect
    into v_tab
    from all_objects  
   where rownum <= 500;          
  obj := json();
  obj_list := json_list(); --an empty structure
  obj2 := json();
  for i in v_tab.first..v_tab.last
  loop
    obj_list.append(json('{"X": '||v_tab(i).x
                       ||',"A": "'||v_tab(i).a||'"'
                       ||',"B": "'||v_tab(i).b||'",'
                       ||'"C": "'||v_tab(i).c||'"}'
                        ).to_json_value);     
  end loop;
  obj.put('row', obj_list);
  obj.htp;  
end;

*In template you can use following tags: {{#row}}, {{/row}}, {{X}}, {{A}}, {{B}}, {{C}}
Mustache.js on GitHub
Mustache.js manual