json
Generates data from a JSON string.
Command properties
| Property | Value |
|---|---|
| Command type | Driver query |
| Required permission | None |
| License usage | Not counted |
| Parallel execution | Not supported |
| Distributed execution | Not supported |
Syntax
json "JSON_DATA"
JSON_DATA- A JSON string enclosed in double quotes (
"). You can provide a JSON object or JSON array. Escape any double quotes inside the JSON string with a backslash (\).
Error codes
Parsing errors
| Error code | Message | Description |
|---|---|---|
| 10200 | json 문자열은 큰 따옴표(")로 시작하고 끝나야 합니다. | The JSON string does not start and end with double quotes |
| 10201 | json 형태의 문자열을 입력하십시오. | The input is not a JSON object or JSON array |
| 10202 | json 파싱에 실패하였습니다. [msg] | JSON parsing failed |
Runtime errors
N/A
Description
The json command parses a JSON string and generates records. It is mainly used to test the behavior of subsequent commands or to generate inline data.
- A JSON object generates 1 record. Key-value pairs in the object are mapped to field-value pairs.
- A JSON array generates one record per element in the array.
- JSON value types (string, number, boolean, null, nested object, array) are automatically mapped.
Examples
-
Generate 1 record from a JSON object
json "{'name':'logpresso', 'version':4}"Generates 1 record containing the
nameandversionfields. -
Generate multiple records from a JSON array
json "[{'src_ip':'192.0.2.1', 'dst_port':80}, {'src_ip':'198.51.100.2', 'dst_port':443}]"Generates 2 records.
-
Generate an empty record and add fields with eval
json "{}" | eval host="192.0.2.10", port=8080Generates an empty record, then uses the eval command to add fields.