Using the Tuple to JSON Operator

Introduction

The Tuple to JSON Java operator converts StreamBase tuples to JSON-encoded data. Each tuple enqueued to the operator results in a single JSON string emitted on its output port.

The operator's input schema determines the set of fields that appear in the generated JSON output. The hierarchy of the fields in the schema matches that of the elements in the JSON. Fields containing null are optionally discarded and may not appear in the JSON output. The incoming schema is duplicated to the output schema and a new user defined field is added which contains the JSON output.

Operator Properties

Property Description
Output Field Name The name of the field to be created in the output schema that contains the JSON converted from the incoming tuple.
Tuple Field The field in the inbound tuple that contains the tuple to convert to JSON. Leave blank to convert the entire inbound tuple.
Include Null Fields Include null fields in the JSON output.
Timestamps as long If enabled, timestamp fields are converted to a long value.
Timestamp Format The format to use when converting timestamp values to a string.
Encode Sub Type The type of transformation that should be used when there are sub-tuples to process.
  • Map — Converting to a map adds field names to the JSON output.

  • List — Converting to a list produces a compact JSON string but does not provide field names.

Enable Status Port If enabled, the status port is made available to receive output status messages.
Log Level Controls the level of verbosity the adapter uses to send notifications to the console. This setting can be higher than the containing application's log level. If set lower, the system log level is used. Available values, in increasing order of verbosity, are: OFF, ERROR, WARN, INFO, DEBUG, TRACE, and ALL.

Operator Ports

The operator has one input port and two output ports to communicate with the surrounding application.

The Tuple to JSON operator's ports are used as follows:

  • TupleIn: The tuple to be converted to JSON. The TupleIn port can be any schema.

  • DataOut: This output port contains all the fields of the TupleIn port with an added user defined field which contains the contents of the generated JSON string

  • Status: A tuple is emitted on this port when an attempt to convert a tuple to an JSON message fails. The Status port has the following schema:

    • type, string: Contains the following value describing the type of event that occurred:

      • Convert

    • action, string: Contains the following value indicating the conversion failed:

      • Failed

    • object, string: Contains a string representation of the input tuple.

    • message, string: Contains a human-readable description of the conversion failure.

    • time, timestamp: Contains the time of the conversion failure.

    • inputTuple, tuple: Contains a copy of the input tuple.