← All articles

Raw JSON in APEX 26.2 Report Queries: Nested Data for Document Generator

APEX 26.2 lets a report query pass JSON columns as raw JSON instead of encoded strings: prefix the column alias with {}. Here is how it works, how it fits Oracle Document Generator, and the rules for data loop names, SQL/JSON functions and instance-level print settings.

AI-readable summary

Oracle APEX 26.2 report queries support complex JSON structures, including hierarchical JSON and JSON columns, as raw JSON that is passed directly to Document Generator. When a report query column holds JSON, prefixing its alias with {} tells APEX that the value must not be encoded as a string in the resulting document; Oracle's example builds a department's employees with json_array and json_object and aliases the column as "{}employees". Oracle recommends SQL/JSON functions such as JSON_OBJECT and JSON_ARRAYAGG rather than string concatenation. Report queries must be SQL statements, not functions returning SQL. With Document Generator or APEX Office Print, the report query's Data Loop Name must match the query source. Document Generator in APEX is the Oracle Document Generator Pre-built Function print server type, configured in Administration Services and used by applications through Use Instance Settings; it works with DOCX and XLSX layouts and produces PDF, DOCX or XLSX output. APEX_PRINT.GENERATE_DOCUMENT remains available for PL/SQL with JSON data.

The short version

Pixel-perfect documents usually need nested data: an invoice with lines, a department with employees, an order with shipments. APEX 26.2 makes that easier in report queries:

  • The change. Report queries support hierarchical JSON and JSON columns “as raw JSON”, passed directly to Document Generator.
  • The switch. Prefix the column alias with {}, for example as "{}employees", and the value is not encoded as a string.
  • The method. Build the JSON with SQL/JSON functions such as JSON_OBJECT and JSON_ARRAYAGG, not string concatenation.
  • The rules. Report queries must be SQL statements, and with Document Generator or APEX Office Print the Data Loop Name must match the report query source.

What changed in 26.2

The release notes list it under Changed Behavior: “Report Queries in APEX now support complex JSON structures, including hierarchical JSON and JSON columns, as raw JSON. This JSON is now passed directly to Document Generator, simplifying advanced document generation and reducing the need for PL/SQL workarounds.”

The App Builder guide documents the mechanism. When the report query returns JSON and one or more columns are in a JSON format, “these columns can be aliased to indicate that the JSON value must not be encoded as a string in the resulting document. The alias needs to be prefixed with” {}.

The {} alias in practice

Oracle’s example nests each department’s employees inside the department row:

select
    d.dname, d.loc, json_array (
        select json_object(e.*) from emp e where e.deptno = d.deptno )
    as "{}employees"
from dept d

Without the prefix, the documentation’s wording implies the employees value reaches the document as a JSON string, which a template cannot loop over. With it, the value arrives as a real array, so the template can repeat a block for each employee. That is the nested shape document templates want, and it no longer needs PL/SQL to assemble.

Oracle's report query that aliases a json_array of employees as {}employees, above a sample data table with three hypothetical department rows. One column shows the employees value as an escaped JSON string with a plain alias, the other shows it as a nested JSON array with the {} prefixed alias
Same data, different alias. With the prefix, the employees value stays a real JSON array.

Oracle adds a tip with the example: use SQL/JSON functions “to construct the JSON being added to the report output. These functions make sure that content is always properly encoded and that the resulting JSON structure is always as expected. Avoid manual string concatenations.” We agree. Hand-built JSON breaks on the first customer name with a quote in it.

Where Document Generator fits

In APEX, Document Generator is the Oracle Document Generator Pre-built Function print server type. Oracle’s description: it lets you “take report query results and convert them from JSON to PDF/Microsoft Office format”, using your own Microsoft Office templates.

A few documented facts shape the setup:

  • Instance level. “Document Generator cannot be selected or added as a print server at the application level. It must be configured in Administration Services.” Applications use it by setting Print Server Type to Use Instance Settings.
  • OCI pieces. The configuration includes a database cloud credential for an OCI user with access to an object storage bucket and the Oracle Document Generator Function.
  • Layouts and output. Layouts are Word or Excel files, and output can be PDF, Word or Excel. The report query download supports PDF, DOCX and XLSX.
  • Data flow. “The APEX engine sends the layout file and the data in JSON format to a remote printing service”, which merges them and returns the document.
  • No generic layouts. The Document Generator print server type and APEX Office Print do not support generic report layouts, so attach a real layout.
Three zones. In the application: a report query with a {} alias, a DOCX or XLSX report layout, and Print Server Type set to Use Instance Settings. In the APEX instance: the APEX engine sends the layout and JSON data, and Administration Services holds the Oracle Document Generator Pre-built Function print server setting. In Oracle Cloud Infrastructure: a cloud credential, an object storage bucket and the Document Generator function, which return a PDF, DOCX or XLSX document
Document Generator is set up once per instance. Apps opt in with Use Instance Settings.

Rules that save debugging time

  • SQL only. “Report queries must be SQL statements. Functions returning SQL statements are not supported.”
  • Data Loop Name. With Document Generator or APEX Office Print, edit the report query to set the Data Loop Name: “The data loop name and the report query source must match.” It is the name APEX gives the array when it prepares the JSON data.
  • Sources. Report query sources include Local Database, REST Enabled SQL, REST Source, Duality View and JSON Source, which covers tables with JSON columns and JSON Collection Tables.
  • One JSON builder. Pick SQL/JSON functions for every nested column, so all of them encode the same way.

When PL/SQL is still the right tool

APEX_PRINT.GENERATE_DOCUMENT stays available when you assemble data in code. Its p_data parameter takes the data for the document, “Currently JSON format only”, and it “can only be used when Oracle Document Generator Pre-built Function is configured as print server in the instance”. For documents driven by one query, the {} alias now covers what used to need that code path.

A short checklist

  • Document Generator configured once in Administration Services
  • Applications set to Use Instance Settings for printing
  • Nested columns built with SQL/JSON functions and aliased with {}
  • Data Loop Name matching the report query source
  • A DOCX or XLSX layout attached, not the generic layout
  • A test document for the largest realistic record, not just one row

Document generation runs across APEX, OCI credentials and storage, so it is a good place for a managed platform. For managed APEX environments with upgrades and support, see Cloud Hosting and the plans page.

Bottom line

Two characters, {}, remove a common reason for PL/SQL glue in document generation. Build nested data with SQL/JSON functions, alias it with the prefix, and let the template loop over a real array.

The rest is setup you do once: Document Generator at instance level, a matching Data Loop Name and a real layout.

FAQ

What does the {} alias prefix do?

It tells APEX that a JSON column’s value must not be encoded as a string in the resulting document, so nested arrays and objects reach the template as JSON.

Which sources can feed a report query?

Report queries can use Local Database, REST Enabled SQL, REST Source, Duality View and JSON Source, including tables with JSON columns and JSON Collection Tables. The query itself must be a SQL statement.

Can I configure Document Generator for a single application?

No. Oracle says it must be configured in Administration Services. Applications use it by setting Print Server Type to Use Instance Settings.

Which formats does Document Generator produce?

PDF, Word and Excel, from Word or Excel layouts.

Why does my document come out empty?

Check the Data Loop Name first. With Document Generator or APEX Office Print, it must match the report query source.

Do I still need APEX_PRINT.GENERATE_DOCUMENT?

Only when you assemble the data in PL/SQL. For a document driven by one report query, the {} alias handles nested JSON directly.

Sources