Previous Topic Next topic Print topic


ENTMF 

The JSON GENERATE Statement

The JSON GENERATE statement converts data to JSON format.

General Format

Syntax Rules

  1. Identifier-1 must be either: an elementary data item of category alphanumeric; an alphanumeric group item; an elementary data item of category national; or a national group item
  2. When identifier-1 is a national group item, identifier-1 is processed as an elementary data item of category national.
  3. When identifier-1 is an alphanumeric group item, identifier-1 is treated as though it were an elementary data item of category alphanumeric.
  4. Identifier-1 must not be defined with the JUSTIFIED clause.
  5. Identifier-1, identifier-2, identifier-4, or identifier-5 cannot be a function identifier.
  6. Identifier-1 can be subscripted or reference modified.
  7. Identifier-1 must not overlap identifier-2 or identifier-3.
  8. The generated JSON text is encoded in UTF-16 big-Endian (codepage 1200) if identifier-1 is of category national; otherwise, it is encoded in UTF-8 (codepage 1208).
  9. Identifier-1 must be large enough to contain the generated JSON text. Typically, it should be from 2 to 3 times the size of identifier-2, depending on the lengths of the data-names within identifier-2. If identifier-1 is not large enough, an exception condition exists at the end of the JSON GENERATE statement. If the COUNT phrase is specified, identifier-3 contains the number of character encoding units that were actually generated.
  10. If the SUPPRESS phrase is in effect, identifier-1 must still be large enough to contain the generated JSON text before suppression.
  11. Identifier-2 cannot be reference modified, but it can be subscripted.
  12. Identifier-2 must not overlap identifier-1 or identifier-3, or must not specify the RENAMES clause.
  13. If identifier-2 is set to any of the following, they are ignored by the JSON GENERATE statement: any subordinate unnamed elementary data items or elementary FILLER data items; any slack bytes inserted for SYNCHRONIZED items; any data item subordinate to identifier-2 that is defined with the REDEFINES clause or that is subordinate to such a redefining item; any data item subordinate to identifier-2 that is defined with the RENAMES clause; and any group data item whose subordinate data items are all ignored.
  14. All data items specified by identifier-2 that are not ignored according to the previous rules must satisfy the following conditions: each elementary data item must have a USAGE other than POINTER, FUNCTION-POINTER, PROCEDURE-POINTER, or OBJECT REFERENCE; there must be at least one such elementary data item; and each non-FILLER data-name must be unique within any immediately superordinate group data item.
  15. Identifier-3 must be an integer data item defined without the symbol P in its picture string.
  16. Identifier-3 must not overlap identifier-1, identifier-2, identifier-4, or identifier-5.
  17. Identifier-4 must reference identifier-2 or one of its subordinate data items.
  18. Identifier-4 or identifier-5 cannot be reference modified or subscripted.
  19. Identifier-4 cannot specify any data item which is ignored by the JSON GENERATE statement.
  20. Literal-1 must be an alphanumeric or national literal containing the name to be generated in the JSON text corresponding to identifier-4.
  21. Identifier-5 must reference a data item that is subordinate to identifier-2 and that is not otherwise ignored by the operation of the JSON GENERATE statement.

General Rules

  1. Identifier-1 is the receiving area for the generated JSON text.
  2. Identifier-2 is the group or elementary data item to be converted to JSON format.
  3. If the COUNT phrase is specified, identifier-3 contains (after successful execution of the JSON GENERATE statement) the count of generated JSON character encoding units. If identifier-1 (the receiver) is of category national, the count is in double-bytes. Otherwise, the count is in bytes.
  4. The NAME phrase enables you to override the default JSON names derived from identifier-2 or its subordinate data items.
  5. If the NAME phrase specifies identifier-4 more than once, the last specification is used.
  6. The SUPPRESS phrase enables you to selectively generate output for the JSON GENERATE statement by allowing you to identify and unconditionally exclude items that are subordinate to identifier-2.
  7. If identifier-5 specifies a group data item, that group data item and all subordinate data items are excluded.
  8. Duplicate specifications of identifier-5 are permitted.
  9. When the SUPPRESS phrase is specified, a group item subordinate to identifier-2 is excluded from the generated JSON text if all eligible items subordinate to the group item are excluded. The outermost object that corresponds to identifier-2 itself is always generated, even if all subordinate items to identifier-2 are excluded. In this case, identifier-2 is assigned the JSON value null. Unless its subordinate items are suppressed, a zero length group also appears in the generated output with the value null.
  10. If the ON EXCEPTION phrase is specified, control transfers to imperative-statement-1 when an error occurs during generation of the JSON document.
  11. If the ON EXCEPTION phrase is not specified, the NOT ON EXCEPTION phrase, if any, is ignored, and control is transferred to the end of the JSON GENERATE statement in the event of an error.
  12. In the event of an error, the JSON-CODE special register contains the exception code; see JSON-CODE Exception Codes for more information.
  13. If an exception condition does not occur during generation of the JSON document, control is passed to imperative-statement-2, if specified; otherwise, control is passed to the end of the JSON GENERATE statement. The ON EXCEPTION phrase, if specified, is ignored, and special register JSON-CODE contains zero after execution of the JSON GENERATE statement.
  14. The END-JSON phrase is the scope terminator that delimits the scope of the statement.
  15. Use of END-JSON allows a conditional JSON GENERATE statement (that is, a JSON GENERATE statement that specifies the ON EXCEPTION or NOT ON EXCEPTION phrase) to be nested in another conditional statement.
  16. The scope of a conditional JSON GENERATE statement can be terminated by either an END-JSON phrase or a separator period.
  17. END-JSON can also be used with a JSON GENERATE statement that does not specify either the ON EXCEPTION or the NOT ON EXCEPTION phrase.
  18. JSON GENERATE statements that appear in imperative-statement-1 or imperative-statement-2 of another JSON GENERATE statement are nested JSON GENERATE statements. Nested JSON GENERATE statements are considered to be matched JSON GENERATE and END-JSON combinations, proceeding from left to right. Thus, any END-JSON phrase that is encountered is matched with the nearest preceding JSON GENERATE statement that has not been implicitly or explicitly terminated.
Previous Topic Next topic Print topic