Splunk Search

Need some help with a JSON array

ScottW
Explorer

Hi smart folks. I have the output of a REST API call as seen below. I need to split each of the records as delimited by the {} as it's own event with each of the key:values defined for each record. 

[

  {

    "name": "ESSENTIAL",

    "status": "ENABLED",

    "compliance": "COMPLIANT",

    "consumptionCounter": 17,

    "daysOutOfCompliance": "-",

    "lastAuthorization": "Dec 11,2024 07:32:21 AM"

  },

  {

    "name": "ADVANTAGE",

    "status": "ENABLED",

    "compliance": "EVALUATION",

    "consumptionCounter": 0,

    "daysOutOfCompliance": "-",

    "lastAuthorization": "Jul 09,2024 22:49:25 PM"

  },

  {

    "name": "PREMIER",

    "status": "ENABLED",

    "compliance": "EVALUATION",

    "consumptionCounter": 0,

    "daysOutOfCompliance": "-",

    "lastAuthorization": "Aug 10,2024 21:10:44 PM"

  },

  {

    "name": "DEVICEADMIN",

    "status": "ENABLED",

    "compliance": "COMPLIANT",

    "consumptionCounter": 2,

    "daysOutOfCompliance": "-",

    "lastAuthorization": "Dec 11,2024 07:32:21 AM"

  },

  {

    "name": "VM",

    "status": "ENABLED",

    "compliance": "COMPLIANT",

    "consumptionCounter": 2,

    "daysOutOfCompliance": "-",

    "lastAuthorization": "Dec 11,2024 07:32:21 AM"

  }

]

Thanks in advance for any help you all might offer to get me down the right track.

Labels (3)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

Assuming this is the output of a search, then make the search do this with that data - this assumes raw is a field containing that data

 

| eval json=json_array_to_mv(raw)
| fields - raw _time
| mvexpand json
| spath input=json
| fields - json

 

0 Karma

ScottW
Explorer

Thank you for the help. This got me to the following:Screenshot 2024-12-12 at 7.56.05 AM.pngScreenshot 2024-12-12 at 7.57.02 AM.png

I am hoping to get to the point where the individual fields like "name" and "consumptionCounter" become their own fields so that I can do things like trend over time, average, etc.

 

0 Karma

ScottW
Explorer

This got me on the right track and let me to the following:Screenshot 2024-12-12 at 8.32.16 AM.png

richgalloway
SplunkTrust
SplunkTrust

It would help to know what you've tried already so we don't waste time on that.

Consider these props settings

[mysourcetype]
DATETIME_CONFIG = current
SHOULD_LINEMERGE = false
LINE_BREAKER = ([\r\n]+)\{
TRANSFORMS-parse_mysourcetype = parse_mysourcetype

with these transforms:

[parse_mysourcetype]
REGEX = "([^"]+)":"([^"]+)
FORMAT = $1::$2
---
If this reply helps you, Karma would be appreciated.
0 Karma

ScottW
Explorer

Hi Rich,

 

I am starting from scratch here and am not a Splunk whisperer, so really starting from ground zero. 

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...