tojson

Converts the values of specified fields to a JSON string.

Command properties

PropertyDescription
Command typeTransforming
Required permissionNone
License usageN/A
Parallel executionSupported
Distributed executionNot supported

Syntax

tojson [output=STR] [FIELD [, FIELD ...]]

Options

output=STR
Name of the output field to store the JSON string (default: _json).

Target

FIELD
Fields to convert to JSON. You can specify multiple fields separated by commas. If omitted, all fields in the record are converted.

Error codes

Parsing errors
Error codeMessageDescription
22300필드가 없습니다.The field list ends with a comma and the next field name is missing
Runtime errors

N/A

Description

The tojson command converts the values of specified fields to a JSON string and assigns the result to the output field. If no fields are specified, all fields in the record are converted to a JSON object.

The result is stored in the field specified by the output option. If output is not specified, the result is stored in the _json field.

Examples

  1. Convert an entire record to JSON

    table duration=1h sys_cpu_logs | tojson output=result
    

    Converts all fields of the record to a JSON string and assigns the result to the result field.

  2. Convert specific fields to JSON

    table duration=1h sys_cpu_logs | tojson output=jsonlog _time, line
    

    Converts only the _time and line fields to a JSON string and assigns the result to the jsonlog field.