makejson

CAUTION: The makejson command is an internal, unsupported, experimental command. See About internal commands.

Description

Creates a JSON object from the specified set of fields in the search results, and places the JSON object into a new field.

Syntax

makejson <wc-field-list> output=<string>

Required arguments

output

Syntax: output=<string>

Description: The name to use for the output field where the JSON object is placed.

Optional arguments

wc-field-list

Syntax: <field>(,<field>) ...

Description: Comma-delimited list of fields to use to generate a JSON object. You can use a wild card character in the field names.

Default: All fields are included in the JSON object if a list is not specified.

Usage

You cannot use the table or fields command to specify the field order in the JSON object that gets created.

Examples

1. Create a JSON object using all of the available fields

The following search create a JSON object in a field called "data" taking in values from all available fields.

  • The makeresults command creates five search results that contain a timestamp.
  • The eval command creates two fields in each search result. One field is named owner and contains the value vladimir. The other field is named error that takes a random number and uses the modulo mathematical operator ( % ) to divide the random number by 3.
  • The makejson command creates a JSON object based on the values in the fields in each search result.

The results look something like this:

2. Create a JSON object from a specific set of fields

Consider the following data:

_time owner error_code
2020-03-10 21:45:14 claudia 1
2020-03-10 20:45:17 alex 4
2020-03-10 06:48:11 wei 2
2020-03-09 21:15:35 david 3
2020-03-09 16:22:10 maria 4
2020-03-08 23:32:56 vanya 1
2020-03-07 14:05:14 claudia 2

The makejson command is used to create a JSON object in a field called "data" using the values from only the _time and owner fields. The error field is not included in the JSON object.

The results look something like this:

3. Create a JSON object using a wildcard list of fields

Create a JSON object in a field called "json-object" using the values from the _time field and fields that end in _owner.

The results look something like this:

4. Use with schema-bound lookups

You can use the makejson command with schema-bound lookups to store a JSON object in the description field for later processing.

Suppose that a Splunk application comes with a KVStore collection called example_ioc_indicators, with the fields key and description. For long term supportability purposes you do not want to modify the collection, but simply want to utilize a custom lookup within a framework, such as Splunk Enterprise Security (ES) Threat Framework.

Let's start with the first part of the search:

This search produces a result that looks something like this:

You would then add the outputlookup command to send the search results to the lookup:

To use this custom lookup within a framework, you would specify this in a search:

See also

Related commands

spath