tojson
Converts the values of specified fields to a JSON string.
Command properties
| Property | Description |
|---|---|
| Command type | Transforming |
| Required permission | None |
| License usage | N/A |
| Parallel execution | Supported |
| Distributed execution | Not 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 code | Message | Description |
|---|---|---|
| 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
-
Convert an entire record to JSON
table duration=1h sys_cpu_logs | tojson output=resultConverts all fields of the record to a JSON string and assigns the result to the
resultfield. -
Convert specific fields to JSON
table duration=1h sys_cpu_logs | tojson output=jsonlog _time, lineConverts only the
_timeandlinefields to a JSON string and assigns the result to thejsonlogfield.