Splunk Search

Parse json array and plot to a line chart

matt-1
Engager

I have the following data that I would like to parse and put into a line chart.  There are millions of rows of data, and I'm looking to find tasks that seem to take the longest.  I can't for the life of me get it to parse, even after reading the many accepted answers.  Any help would be greatly appreciated.

Here's a sample of the data.

 

 

{
    "latency_info": [{
            "started": "0",
            "task": "Start"
        }, {
            "started": "0",
            "task": "api-routing"
        }, {
            "started": "1",
            "task": "api-cors"
        }, {
            "started": "1",
            "task": "api-client-identification"
        }, {
            "started": "1",
            "task": "api-rate-limit"
        }, {
            "started": "1",
            "task": "api-security"
        }, {
            "started": "1",
            "task": "api-execute"
        }, {
            "started": "1",
            "task": "assembly-invoke"
        }, {
            "started": "2",
            "task": "api-result"
        }
    ]
}

 

 

 

Labels (2)
0 Karma
1 Solution

michel_wolf
Path Finder

Hi Matt,

maybe you can try something like this:

source="test.json" host="splunk-aio01" sourcetype="_json"
|rename latency_info{}.started as started, latency_info{}.task as task
| eval temp_field=if(isnotnull(task),mvzip(started, task),"")
| mvexpand temp_field
| makemv temp_field delim=","
| eval started=mvindex(temp_field,0)
| eval task=mvindex(temp_field,1)
|stats sum(started) by task

Michel

View solution in original post

michel_wolf
Path Finder

Hi Matt,

maybe you can try something like this:

source="test.json" host="splunk-aio01" sourcetype="_json"
|rename latency_info{}.started as started, latency_info{}.task as task
| eval temp_field=if(isnotnull(task),mvzip(started, task),"")
| mvexpand temp_field
| makemv temp_field delim=","
| eval started=mvindex(temp_field,0)
| eval task=mvindex(temp_field,1)
|stats sum(started) by task

Michel

matt-1
Engager

Michel,

Thanks for the response!  It seems that the problem is my data.  I didn't mention it, and didn't want to post the full data set, but the json, while at the root level, does have other data.  I added just the latency data to my instance and the line chart worked perfectly.  Do you happen to know what to do if there's other data in the json message?  If possible, I can just do a field extraction and parse that data, though I haven't been able to find examples of doing that. Here's a sample of the other information that isn't needed in the chart:

 

{
    "rate_limit": {
        "default": {
            "reject": "false",
            "shared": "true",
            "count": "94",
            "limit": "100",
            "period": "1",
            "unit": "hour",
            "interval": "1"
        }
    },
    "@version": "1",
    "request_method": "GET",
    "datetime": "2021-07-12T14:24:41.162Z",
    "time_to_serve_request": "2",
    "bytes_sent": "0",
    "request_http_headers": [],
    "headers": {
        "content_length": "1939",
        "http_accept": null,
        "http_version": "HTTP/1.0",
        "connection": "close",
        "http_user_agent": null
    },
    "response_http_headers": [],
    "latency_info": [{
            "started": "0",
            "task": "Start"
        }, {
            "started": "0",
            "task": "api-routing"
        }, {
            "started": "1",
            "task": "api-cors"
        }, {
            "started": "1",
            "task": "api-client-identification"
        }, {
            "started": "1",
            "task": "api-rate-limit"
        }, {
            "started": "1",
            "task": "api-security"
        }, {
            "started": "1",
            "task": "api-execute"
        }, {
            "started": "1",
            "task": "assembly-invoke"
        }, {
            "started": "2",
            "task": "api-result"
        }
    ],
    "response_body": "",
    "status_code": "200 OK",
    "transaction_id": "123456789",
    "request_protocol": "https",
    "request_body": ""
}

 

 

 

 

0 Karma

michel_wolf
Path Finder

Hi Matt,

I tried this again with your new data and for me the search was the same to receive the results, maybe you have other field names for this here
|rename latency_info{}.started as started, latency_info{}.task as task

just look in some of your data and make sure if you look to the interesting fields the name for the started and task field are the same as in my rename command here, if not you have just to edit the rename command.

0 Karma
Get Updates on the Splunk Community!

New in Splunk Observability Cloud: Automated Archiving for Unused Metrics

Automated Archival is a new capability within Metrics Management; which is a robust usage & cost optimization ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

What's New in Splunk Observability - July 2025

What’s New?  We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what ...