spath command: Examples

Examples for using the SPL2 spath command

Extract nested JSON data from an existing field

The following example shows how to extract nested JSON data:

Suppose you run the following search, which creates a nested JSON object about cooperative board games.

PYTHON
When you run this search it creates a field called category with the following nested object:
category
[ {"boardgames": [ { "cooperative": [ { "name": "Pandemic"}, { "name": "Forbidden Island"}, { "name": "Castle Panic"} ] } ] } ]

You can add the spath command to a search to extract a specific value from the object. In this example the game Forbidden Island is extracted:

PYTHON

Extracting information by specifying an output field and path

The following example shows how to specify an output field and path:

CODE

Extracting information by specifying an output field and path with a wildcard for JSON data

The following example shows how to specify an output field and path with a wildcard for JSON data:

CODE

Extracting the value of the locale attribute in XML data

The following example shows how to extract the value of the locale attribute in XML data. Because the output field name contains a special character, a period ( . ), the field name must be enclosed in quotation marks.

CODE

Extracting data from a JSON file using the auto-extract mode

Consider the following example of JSON in an event:

JSON
json
{
   "vendorProductSet" : {
      "product" : [
         {"desc" : 1},
         {"locDesc" : 2}
      ],
      "year" : 2026
    }
}

The following is an example of using the spath command in a search without the optional parameters:

CODE
... | spath

This search extracts and creates the following field-value pairs:

See also