OUTPUT JSON Files

[attr := ] OUTPUT(recordset, [ format ] ,file ,JSON [ (jsonoptions) ] [,ENCRYPT( key ) ] [, CLUSTER( target ) ] [, OVERWRITE ][, UPDATE] [, EXPIRE( [ days ] ) ] )

CLUSTEROptional. Specifies writing the file to the specified list of target clusters. If omitted, the file is written to the cluster on which the workunit executes. The number of physical file parts written to disk is always determined by the number of nodes in the cluster on which the workunit executes, regardless of the number of nodes on the target cluster(s).
targetA comma-delimited list of string constants containing the names of the clusters to write the file to. The names must be listed as they appear on the ECL Watch Activity page or returned by the Std.System.Thorlib.Group() function, optionally with square brackets containing a comma-delimited list of node-numbers (1-based) and/or ranges (specified with a dash, as in n-m) to indicate the specific set of nodes to write to.
ENCRYPTOptional. Specifies writing the file to disk using both 256-bit AES encryption and LZW compression.
keyA string constant containing the encryption key to use to encrypt the data.
OVERWRITEOptional. Specifies overwriting the file if it already exists.
UPDATESpecifies that the file should be rewritten only if the code or input data has changed.
EXPIREOptional. Specifies the file is a temporary file that may be automatically deleted after the specified number of days.
daysOptional. The number of days after which the file may be automatically deleted. If omitted, the default is seven (7).

This form writes the recordset to the specified file as JSON data with the name of each field in the specified format becoming the JSON tag for that field's data. The valid set of jsonoptions are:

'rowtag'

HEADING( headertext [, footertext ] )

TRIM

OPT

rowtagThe text to place in record delimiting tag.
HEADINGSpecifies placing header and footer records in the file.
headertextThe text of the header record to place in the file.
footertextThe text of the footer record to place in the file.
TRIMSpecifies removing trailing blanks from string fields before output.
OPTSpecifies omitting tags for any empty string field from the output.

If no jsonoptions are specified, the defaults are:

         JSON('Row',HEADING('[',']'))

Example:

R := {STRING10 fname,STRING12 lname};
B := DATASET([{'Fred','Bell'},{'George','Blanda'},{'Sam',''}],R);

OUTPUT(B,,'fred1.json', JSON); // writes B to the fred1.json file
/* the Fred1.json file looks like this:
{"Row": [
{"fname": "Fred      ", "lname": "Bell        "},
{"fname": "George    ", "lname": "Blanda      "},
{"fname": "Sam       ", "lname": "            "}
]}
*/
OUTPUT(B,,'fred2.json',JSON('MyResult', HEADING('[', ']')));
/* the Fred2.json file looks like this:
["MyResult": [
{"fname": "Fred      ", "lname": "Bell        "},
{"fname": "George    ", "lname": "Blanda      "},
{"fname": "Sam       ", "lname": "            "}
]]