JSON command examples
These examples present complete JCL for converting log data to JSON format.
Where an example shows only a SYSIN data set, the JCL is the same as the preceding example.
Converting all fields to JSON Lines
The following JCL extracts a single CICS® monitoring facility (CMF) performance class record from the dumped SMF data set 'HLQ.SMF.DAILY', converts the data to JSON Lines, and then writes the JSON Lines data to SYSOUT:
//UIDFUW JOB NOTIFY=&SYSUID
//FUWBATCH EXEC PGM=FUWBATCH
//STEPLIB DD DISP=SHR,DSN=<FUW HLQ>.SFUWLINK
//SMFIN DD DISP=SHR,DSN=HLQ.SMF.DAILY
//JSON DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
JSON CODE(CMF) OUTLIM(1)
/*
The OUTLIM parameter is useful for testing, to restrict processing to a limited number of output records.
The JSON output is encoded in EBCDIC code page 1047, the default encoding of the JSON command.
The following JCL produces similar output, but reads today's first CMF record from an SMF log stream, instead of reading the first CMF record from a data set. A LOGSTREAM command at the start of the SYSIN data set replaces the SMFIN DD statement in the previous JCL.
//UIDFUW JOB NOTIFY=&SYSUID
//FUWBATCH EXEC PGM=FUWBATCH
//STEPLIB DD DISP=SHR,DSN=<FUW HLQ>.SFUWLINK
//JSON DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
LOGSTREAM SMF:IFASMF.PROD
START 0 /* Today
JSON CODE(CMF) OUTLIM(1)
/*
The following JCL extracts all DB2® system statistics trace (IFCID 001) records from a dumped SMF data set, converts the data to JSON Lines, and then writes the data to an MVS sequential data set:
//UIDFUW JOB NOTIFY=&SYSUID
//FUWBATCH EXEC PGM=FUWBATCH
//STEPLIB DD DISP=SHR,DSN=<FUW HLQ>.SFUWLINK
//SMFIN DD DISP=SHR,DSN=HLQ.SMF.DAILY
//JSON DD DSN=MY.FUW.JSON,DISP=(NEW,CATLG),
// UNIT=SYSDA,SPACE=(CYL,(10,10),RLSE)
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
JSON CODE(DTR:001)
/*
The previous examples write each line of JSON Lines to a separate record in EBCDIC, with no end-of-line markers.
The following JCL writes JSON Lines to a z/OS®
UNIX file in EBCDIC, with a newline character (X'0A') at the
end of each line. The output DD statement specifies FILEDATA=TEXT
:
//UIDFUW JOB NOTIFY=&SYSUID
//FUWBATCH EXEC PGM=FUWBATCH
//STEPLIB DD DISP=SHR,DSN=<FUW HLQ>.SFUWLINK
//SMFIN DD DISP=SHR,DSN=HLQ.SMF.DAILY
//JSON DD PATH='/u/myid/fuw.json',
// FILEDATA=TEXT,
// PATHOPTS=(OWRONLY,OCREAT,OEXCL),
// PATHDISP=(KEEP,DELETE),
// PATHMODE=(SIRUSR,SIWUSR,SIRGRP)
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
JSON CODE(DTR:001)
/*
The following JCL writes JSON Lines to a z/OS
UNIX file in ASCII, with a line feed character (X'0A') at the
end of each line. The output DD statement specifies FILEDATA=BINARY
and the
JSON command specifies ASCII EOL(LF)
:
//UIDFUW JOB NOTIFY=&SYSUID
//FUWBATCH EXEC PGM=FUWBATCH
//STEPLIB DD DISP=SHR,DSN=<FUW HLQ>.SFUWLINK
//SMFIN DD DISP=SHR,DSN=HLQ.SMF.DAILY
//JSON DD PATH='/u/myid/fuw.json',
// FILEDATA=BINARY,
// PATHOPTS=(OWRONLY,OCREAT,OEXCL),
// PATHDISP=(KEEP,DELETE),
// PATHMODE=(SIRUSR,SIWUSR,SIRGRP)
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
JSON CODE(DTR:001) ASCII EOL(LF)
/*
Specifying which fields to extract
By default, the JSON command extracts all fields of the selected record type.
There are several methods for specifying which fields to extract. The most straightforward method is to follow the JSON command with a FIELDS command that specifies a list of field names:
JSON LINES CODE(SMF:30.)
FIELDS(
SMF30JBN
SMF30SIT
SMF30STD
SMF30CPT
)
Selecting which records to extract
To select which records to extract, follow the JSON command with a CODE command and subsequent COND statements that specify filter conditions.
The following example selects SMF type 30 records where both of the following conditions are true:
- The record is for a job step termination
- The job owner is MYID
JSON LINES CODE(SMF:30.)
FIELDS(
SMF30JBN
SMF30SIT
SMF30STD
SMF30CPT
)
CODE(SMF:30.) /* Must match CODE parameter of JSON command
COND SMF30STP EQ 5 /* Record subtype for job step termination
COND SMF30RUD EQ 'MYID' /* RACF user ID of the job owner
Extracting multiple record types from an SMF log stream to z/OS UNIX files
The following JCL extracts two types of record written today to an SMF log stream, converts them to JSON Lines in ASCII, and then writes each record type to a separate z/OS UNIX file:
//UIDFUW JOB NOTIFY=&SYSUID
//FUWBATCH EXEC PGM=FUWBATCH
//STEPLIB DD DISP=SHR,DSN=<FUW HLQ>.SFUWLINK
//CMF DD PATH='/u/myid/cmf.json',
// PATHOPTS=(OWRONLY,OCREAT),
// PATHDISP=(KEEP,DELETE),
// PATHMODE=(SIRUSR,SIWUSR,SIRGRP),
// FILEDATA=BINARY
//SMF30 DD PATH='/u/myid/smf30.json',
// PATHOPTS=(OWRONLY,OCREAT),
// PATHDISP=(KEEP,DELETE),
// PATHMODE=(SIRUSR,SIWUSR,SIRGRP),
// FILEDATA=BINARY
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
LOGSTREAM SMF:IFASMF.PROD
START 0
JSON CODE(CMF) OUTPUT(CMF) +
TIMEFORMAT(ISO8601) ASCII EOL(LF)
JSON CODE(SMF:30.) OUTPUT(SMF30) +
TIMEFORMAT(ISO8601) ASCII EOL(LF)
/*
Writing JSON that preserves the structure of the original log records
Some types of log record can contain multiple instances of the same section, also known as
repeating sections. By default, repeating sections are merged in the JSON output into a single
section with a single set of fields. To keep repeating sections separate, represented in JSON as
array elements, use the HORIZONTALSECTIONS parameter. For example, to keep all
repeating sections separate, specify HORIZONTALSECTIONS(ALL)
.
The following JCL creates a JSON file on z/OS UNIX that you can parse to reproduce the structure of the original log record, including repeating sections:
//UIDFUW JOB NOTIFY=&SYSUID
//FUWBATCH EXEC PGM=FUWBATCH
//STEPLIB DD DISP=SHR,DSN=<FUW HLQ>.SFUWLINK
//SMFIN DD DISP=SHR,DSN=HLQ.SMF.DAILY
//JSON DD PATH='/u/myid/fuw.json',
// PATHOPTS=(OWRONLY,OCREAT,OTRUNC),
// FILEDATA=BINARY
//METADATA DD SYSOUT=*
//SCHEMA DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
JSON CODE(DTR:001) +
HORIZONTALSECTIONS(ALL) +
METADATA(METADATA) +
TIMEFORMAT(ISO8601) ASCII EOL(LF)
/*
This example also demonstrates using the OUTPATH parameter to write directly to a z/OS UNIX file, as an alternative to using the OUTPUT parameter to write to a ddname that refers a z/OS UNIX file.