Splunk Search

Extract the fields from JSON in search time and write a search

vasanthmss
Motivator
_raw = {"studentsmarks":{"subject":"science","university":"university1","examdate":"10-12-14"},"students":[{"college":"college1","studentname":"name1","mark":"98"},{"college":"college1","studentname":"name2","mark":"99"},{"college":"college2","studentname":"name21","mark":"80"},{"college":"college2","studentname":"name22","mark":"100"}]}

JSON Format

{
  "studentsmarks": {
    "subject": "science",
    "university": "university1",
    "examdate": "10-12-14"
  },
  "students": [
    {
      "college": "college1",
      "studentname": "name1",
      "mark": "98"
    },
    {
      "college": "college1",
      "studentname": "name2",
      "mark": "99"
    },
    {
      "college": "college2",
      "studentname": "name21",
      "mark": "80"
    },
    {
      "college": "college2",
      "studentname": "name22",
      "mark": "100"
    }
  ]
}

Expected results,

college studentname mark subject university examdate
college1    name1   98  science university1 10-12-14
college1    name2   99  science university1 10-12-14
college2    name21  80  science university1 10-12-14
college2    name22  100 science university1 10-12-14
V
1 Solution

somesoni2
Revered Legend

Here you go (runanywhere sample)

| gentimes start=-1 | eval temp="{\"studentsmarks\":{\"subject\":\"science\",\"university\":\"university1\",\"examdate\":\"10-12-14\"},\"students\":[{\"college\":\"college1\",\"studentname\":\"name1\",\"mark\":\"98\"},{\"college\":\"college1\",\"studentname\":\"name2\",\"mark\":\"99\"},{\"college\":\"college2\",\"studentname\":\"name21\",\"mark\":\"80\"},{\"college\":\"college2\",\"studentname\":\"name22\",\"mark\":\"100\"}]}" | table temp | rename temp as _raw | spath | rename students{}.* as * | eval temp=mvzip(college,mvzip(mark,studentname,"#"),"#") | mvexpand temp | rex field=temp "(?<college>.*)#(?<mark>.*)#(?<studentname>.*)" | fields - temp,_raw

View solution in original post

somesoni2
Revered Legend

Here you go (runanywhere sample)

| gentimes start=-1 | eval temp="{\"studentsmarks\":{\"subject\":\"science\",\"university\":\"university1\",\"examdate\":\"10-12-14\"},\"students\":[{\"college\":\"college1\",\"studentname\":\"name1\",\"mark\":\"98\"},{\"college\":\"college1\",\"studentname\":\"name2\",\"mark\":\"99\"},{\"college\":\"college2\",\"studentname\":\"name21\",\"mark\":\"80\"},{\"college\":\"college2\",\"studentname\":\"name22\",\"mark\":\"100\"}]}" | table temp | rename temp as _raw | spath | rename students{}.* as * | eval temp=mvzip(college,mvzip(mark,studentname,"#"),"#") | mvexpand temp | rex field=temp "(?<college>.*)#(?<mark>.*)#(?<studentname>.*)" | fields - temp,_raw
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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

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