Splunk Search

After receiving "External search command 'jsonfields' returned error code 1", how to extract fields from a JSON input?

rodneyjerome
Explorer

Hi,
I am trying to extract fields from a JSON input. I don't understand if I am making any mistake in getting the events or in output. Below is my python script:

import splunk.Intersplunk

json_events = splunk.Intersplunk.readResults(None, None, True)

for json_event in json_events:
    json_data = json.load(json_event)
    fields = (json_data['Fields'])
    for f in fields:
        if not f['values']:
            json_event[f['Name']] = 'null'
        elif 'value' not in f['values'][0]:
            json_event[f['Name']] = 'null'
        else:
            json_event[f['Name']] = f['values'][0]['value']

splunk.Intersplunk.outputResults(json_events)

and the below snippet is a sample json event.

{
  "Type": "defect",
  "Fields": [
    {
      "values": [],
      "Name": "ut2"
    },
    {
      "values": [
        {
          "value": "SF"
        }
      ],
      "Name": "ut3"
    },
    {
      "values": [
        {
          "value": "2"
        }
      ],
      "Name": "vs"
    },
    {
      "values": [
        {
          "value": "N"
        }
      ],
      "Name": "attached"
    },
    {
      "values": [
        {
          "value": "vh"
        }
      ],
      "Name": "pri"
    },
],
}

I have stored them as dictionary (key, value pairs). I am getting error "External search command 'jsonfields' returned error code 1"
any suggestions?

Thanks in advance

0 Karma
1 Solution

Flynt
Splunk Employee
Splunk Employee
0 Karma

rodneyjerome
Explorer

sure i will try that and get back to you

0 Karma

rodneyjerome
Explorer
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...

Keep the Learning Going with the New Best of .conf Hub

Hello Splunkers, With .conf26 getting closer, there’s already a lot of excitement building around this year’s ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...