On this page
json command
Read fields out of JSON held inside a field. Names every key it finds unless you name the paths yourself.
Reads fields out of JSON held inside a field, such as a log line whose message is a JSON object. The fields exist for this query only.
With no paths named, it creates a column for every key it finds in a sample of the matching events. Name paths to choose exactly which values to read and what to call them.
Syntax
ObiQL
| json [field=<field>] [<path>[:<type>] [AS <name>] [, ...]]Square brackets mark an optional part, and angle brackets a value you supply.
Arguments
| Argument | Required | Description |
|---|---|---|
field=<field> | Optional | The field holding the JSON. Defaults to message. input= is accepted as another spelling. |
<path> | Optional | A key (country), a dotted path ($.user.id), or a path with an array index, which must be quoted because brackets are query syntax ("items[0].sku"). Nested objects become dotted column names such as cart.items. Separate paths with commas. |
:<type> | Optional | :number, :string or :raw sets the value's type. Without it, the type is taken from the sampled data, falling back to text. |
AS <name> | Optional | Names the resulting column. Without it, the column is named after the path. |
Usage
- A missing path, or an event whose field is not JSON, gives an empty value. The row is kept.
- json must come before stats or timechart.
- Fields it creates can be filtered with where, grouped, sorted and projected, and replace a stored field of the same name.
Examples
1. Every key in a JSON message
ObiQL
| json field=messageAdds one column per key found in the sampled events.
2. Only the keys you need
ObiQL
| json field=message country, tagCreates just the country and tag columns.
3. Nested values with names and types
ObiQL
| json field=message $.user.id AS user_id, duration_ms:number | stats avg(duration_ms) by user_idReads a nested value under a new name, forces a number type, then aggregates.