Operation of JSON GENERATE
The content of each eligible elementary data item within identifier-2 that has not been excluded from JSON generation according to a SUPPRESS phrase, is converted to character format in the resulting JSON text.
Only the first definition of each storage area is processed. Redefinitions of data items are not included. Data items that are effectively defined by the RENAMES clause are also not included.
The JSON names are obtained from the NAME phrase if specified; otherwise by default they are derived from the data-names within identifier-2 as described in JSON name formation. The names of group items that contain the selected elementary items are retained as the names of parent JSON objects.
No extra white space (new lines, indentation, and so forth) is inserted to make the generated JSON text more readable.
If the receiving area specified by identifier-1 is not large enough to contain the resulting JSON text, an exception condition exists. See the description of the ON EXCEPTION phrase above for details.
If identifier-1 is longer than the generated JSON text, only that part of identifier-1 in which JSON is generated is changed. The rest of identifier-1 contains the data that was present before this execution of the JSON GENERATE statement.
To avoid referring to that data, either initialize identifier-1 to spaces before the JSON GENERATE statement or specify the COUNT phrase.
If the COUNT phrase is specified, identifier-3 contains (after successful execution of the JSON GENERATE statement) the total number of character positions (UTF-16 code points, UTF-8 code points or bytes) that were generated. You can use identifier-3 as a reference modification length field to refer to the part of identifier-2 that contains the generated JSON text.
After execution of the JSON GENERATE statement, special register JSON-CODE contains either zero, which indicates successful completion, or a nonzero exception code. For details, see JSON GENERATE exceptions in the Enterprise COBOL Programming Guide.
The JSON PARSE statement also uses special register JSON-CODE. Therefore if you code a JSON GENERATE statement in the processing procedure of a JSON PARSE statement, save the value of JSON-CODE before that JSON GENERATE statement executes and restore the saved value after the JSON GENERATE statement terminates.
A byte order mark is not generated for JSON texts.