The below code uses the Progress.Json.ObjectModel.JsonObject class to generate the JSON output:
USING Progress.Json.ObjectModel.JsonObject.
DEFINE TEMP-TABLE invoice
FIELD internalid AS CHARACTER.
DEFINE TEMP-TABLE notes
FIELD invoice_note AS CHARACTER
FIELD apply_invoice_note AS CHARACTER
FIELD apply_reference AS CHARACTER.
DEFINE VARIABLE oJson AS JsonObject NO-UNDO.
DEFINE VARIABLE oJsonInvoice AS JsonObject NO-UNDO.
DEFINE VARIABLE oJsonNotes AS JsonObject NO-UNDO.
DEFINE VARIABLE jSon_string AS CHARACTER NO-UNDO.
/* Create a record in each of the temp-tables */
CREATE invoice.
invoice.internalid = "5071517".
CREATE notes.
ASSIGN notes.invoice_note = "note from PROGRESSS"
notes.apply_invoice_note = "apply note"
notes.apply_reference = "apply reference".
/* Create new JsonObjects */
oJson = NEW JsonObject().
oJsonInvoice = NEW JsonObject().
oJsonNotes = NEW JsonObject().
/* Add the Invoice table */
oJson:Add("invoice", oJsonInvoice).
oJsonInvoice:READ(TEMP-TABLE invoice:HANDLE).
/* Add the Notes table */
oJson:Add("notes", oJsonNotes).
oJsonNotes:READ(TEMP-TABLE notes:HANDLE).
/* Write the JSON string to a character variable */
oJson:Write(jSon_string,TRUE).
MESSAGE STRING(jSon_string) VIEW-AS ALERT-BOX.