Consider the need to embed support for a DOM menu object that contains a submenu with a number of choices. The snippet below is an example of the type of prior planning of how to use the tools is needed to build the JSON from the inside out.
The snippet below breaks the process done into five steps.
// STEP 1) Build the submenu Key-Value pairs
// STEP 2) Build the array of submenu key items
// With C_OBJECT declared vars, APPEND TO ARRAY makes
// use of the 4D Array zero element.
APPEND TO ARRAY($Items_aO;$Ele1_O)
APPEND TO ARRAY($Items_aO;$Ele2_O)
APPEND TO ARRAY($Items_aO;$Ele3_O)
// STEP 3) Encode the submenu elements into the "$Items_O" object
OB SET ARRAY($Items_O;"Items";$Items_aO)
// STEP 4) Encode the submenu "$Menu_O" object
// STEP 5) Now it can be sent to web page or the Pasteboard
WEB SEND TEXT($JSON_T)
SET TEXT TO PASTEBOARD($JSON_T)