Consider a basic page such as this one.

The button executes a dynamic action that populates an item based on some PL/SQL.

The 'raw' example populates P5_RAW with a JSON literal string.

P5_PKG is populated using apex_json
apex_json.initialize_clob_output;
apex_json.open_array;
apex_json.open_object;
apex_json.write('type', 'empty');
apex_json.close_object;
apex_json.close_array;
:P5_PKG := apex_json.get_clob_output;
apex_json.free_output;
The test case I just built in 18.2 works fine, but the P5_PKG case gave me an error in 5.1.3 (on 12.1)

This took me some time to isolate, and it appears the APEX_JSON package is conflicting with the mechanics of the 'Page items to return' attribute.
Interesting to see it's no longer a problem, but I'd really like to understand why.
And is there a workaround to allow usage of APEX_JSON, instead of building JSON manually, particularly this is on db 12.1.
Cheers