Serializing a JSON document

You can serialize a JSON document to a data stream by using the tpf_dfdl_serializeDoc or the tpf_dfdl_serializeData function.

Before you begin

Load the DFDL schema files to the z/TPF system by using common deployment.

About this task

The procedure for serializing your JSON document is dependent on whether the elements in your JSON document are ordered or unordered. That is, if the order of the elements in your JSON document matches the order of elements in the associated DFDL schema, you can use the tpf_dfdl_serializeDoc function. However, if the elements in your JSON document are in a different order, you must use the tpf_dfdl_serializeData function.

Procedure

  • To serialize a JSON document that contains elements in the same order as the DFDL schema, complete the following steps:
    1. Call the tpf_dfdl_initialize_handle or tpf_dfdl_createChildHandle function to initialize a DFDL handle that will be used on the following z/TPF DFDL API call to serialize the JSON document.
    2. Call the tpf_dfdl_serializeDoc function to serialize the JSON document to a data stream.
    3. Call the tpf_dfdl_terminate_handle function to release any storage that was created by the DFDL APIs.
  • To serialize a JSON document that contains unordered elements, complete the following steps:
    1. Call the tpf_doc_initialize_handle function to initialize a z/TPF parser API handle that will be used on following z/TPF parser API calls to parse the JSON document. Pass a null pointer for the JSON structure pointer and specify the B2B_JSON_PARSER value for the parser type.
    2. Call the tpf_doc_parseDocument function to parse the JSON document into a tree structure.
    3. Call the tpf_dfdl_initialize_handle function with the schema_file and root_element parameters specified. The parameters define the JSON document that you want to map to a data stream.
    4. Call the tpf_dfdl_serializeData function to serialize the tree structure into a data stream.
    5. Store the pointer that is returned for the data stream that was created in the previous step in an appropriate location.
    6. Call the tpf_doc_terminate_handle function to release any storage that was created by the parser APIs.
    7. Call the tpf_dfdl_terminate_handle function to release any storage that was created by the DFDL APIs.