Getting Data In

Extract multiple jsons from array

amitdaniel
Explorer

Hi all .

This is an example of a json i'm sending to my Splunk cloud.

{   "workers": [
    {
      "UserID": 100000906,
      "ActiveShiftName": "learning sports",
      "WorkerName": "tim",
      "CurrentRoleInShift": "Tagger",
      "IsLogged": true,
      "TimeFromLastEventSaved": "00:00:13.2323651",
      "TimeFromLastEventApproved": null,
      "TotalEventsSavedInPast30Min": 68,
      "TotalEventsApprovedInPast30Min": 0
    },
    {
      "UserID": 100002137,
      "ActiveShiftName": "learning sports",
      "WorkerName": "liverpool2",
      "CurrentRoleInShift": null,
      "IsLogged": false,
      "TimeFromLastEventSaved": null,
      "TimeFromLastEventApproved": null,
      "TotalEventsSavedInPast30Min": 0,
      "TotalEventsApprovedInPast30Min": 0
    }   ] }

I would like to build a table with this fields :
workers{}.active_shift_name
workers{}.worker_name
workers{}.worker_id CurrentRoleInShift
workers{}.TimeFromLastEventSaved
workers{}.TimeFromLastEventApproved
workers{}.IsLogged

I tried multiple commands with no success
For an example I tried this command :

index="Test1" | spath input=_raw path="workers{}.ActiveShiftName" output=active_shift_name | spath input=_raw path="workers{}.WorkerName" output=worker_name |spath input=_raw path="workers{}.UserID" output=worker_id |spath input=_raw path="workers{}.CurrentRoleInShift" output=CurrentRoleInShift |spath input=_raw path="workers{}.TimeFromLastEventSaved" output=TimeFromLastEventSaved |spath input=_raw path="workers{}.TimeFromLastEventApproved" output=TimeFromLastEventApproved |spath input=_raw path="workers{}.TotalEventsSavedInPast30Min" output=TotalEventsSavedInPast30Min |spath input=_raw path="workers{}.TotalEventsApprovedInPast30Min" output=TotalEventsApprovedInPast30Min |spath input=_raw path="workers{}.IsLogged" output=IsLogged  | table active_shift_name worker_name worker_id CurrentRoleInShift TimeFromLastEventSaved TimeFromLastEventApproved IsLogged

Can you please help ?

Thank you!
Amit

0 Karma
1 Solution

chinmoya
Communicator

path="workers{}.ActiveShiftName"

Use need to enclose each field in quotes. See attachment.

alt text

View solution in original post

0 Karma

amitdaniel
Explorer

Thank you @chinmoya !!!

chinmoya
Communicator

path="workers{}.ActiveShiftName"

Use need to enclose each field in quotes. See attachment.

alt text

0 Karma

vnravikumar
Champion

Hi

Try this and rename the columns as required

| makeresults 
| eval test=" {   \"workers\": [
     {
       \"UserID\": 100000906,
       \"ActiveShiftName\": \"learning sports\",
       \"WorkerName\": \"tim\",
       \"CurrentRoleInShift\": \"Tagger\",
       \"IsLogged\": true,
       \"TimeFromLastEventSaved\": \"00:00:13.2323651\",
       \"TimeFromLastEventApproved\": null,
       \"TotalEventsSavedInPast30Min\": 68,
       \"TotalEventsApprovedInPast30Min\": 0
     },
     {
       \"UserID\": 100002137,
       \"ActiveShiftName\": \"learning sports\",
       \"WorkerName\": \"liverpool2\",
       \"CurrentRoleInShift\": null,
       \"IsLogged\": false,
       \"TimeFromLastEventSaved\": null,
       \"TimeFromLastEventApproved\": null,
       \"TotalEventsSavedInPast30Min\": 0,
       \"TotalEventsApprovedInPast30Min\": 0
     }   ] }" 
| spath input=test 
| table workers{}.ActiveShiftName, workers{}.WorkerName,workers{}.CurrentRoleInShift,workers{}.TimeFromLastEventSaved,workers{}.TimeFromLastEventApproved,workers{}.IsLogged
0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...