json

Generates data from a JSON string.

Command properties

PropertyValue
Command typeDriver query
Required permissionNone
License usageNot counted
Parallel executionNot supported
Distributed executionNot 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 codeMessageDescription
10200json 문자열은 큰 따옴표(")로 시작하고 끝나야 합니다.The JSON string does not start and end with double quotes
10201json 형태의 문자열을 입력하십시오.The input is not a JSON object or JSON array
10202json 파싱에 실패하였습니다. [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

  1. Generate 1 record from a JSON object

    json "{'name':'logpresso', 'version':4}"
    

    Generates 1 record containing the name and version fields.

  2. 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.

  3. Generate an empty record and add fields with eval

    json "{}" | eval host="192.0.2.10", port=8080
    

    Generates an empty record, then uses the eval command to add fields.