Monitoring Splunk

How do you parse the following JSON data?

ips_mandar
Builder

Hi,

I want to parse below json data .Below is one sample event-
Objabco.codecnullavro.schema�{"type":"record","name":"Eventtable","namespace":"abc.cdf.ghi","fields":[{"name":"SequenceNumber","type":"long"},{"name":"Offset","type":"string"},{"name":"EnqueuedTimeUtc","type":"string"},{"name":"SystemProperties","type":{"type":"map","values":["long","double","string","bytes"]}},{"name":"Properties","type":{"type":"map","values":["long","double","string","bytes","null"]}},{"name":"Body","type":["null","bytes"]}]}O����D���=XTPO����D���=XTP

I tried spath but unable to get success. Can anyone help me to parse this json data

Tags (1)
0 Karma
1 Solution

whrg
Motivator

Hello @ips_mandar,

Your sample event does not consist of strict JSON data because of the non-JSON prefix and suffix.

I suggest you extract the JSON data as a new field and then run spath on this field:

yourbasesearch
| rex field=_raw "(?<json_data>\{.+\})"
| spath input=json_data

The regex above is defined very broadly. Your sample event is full of strange symbols. So you might want to improve the regular expression.

Ideally, you would index pure JSON data in Splunk and set the sourcetype to json. This way, the JSON data gets parsed automatically.

View solution in original post

0 Karma

whrg
Motivator

Hello @ips_mandar,

Your sample event does not consist of strict JSON data because of the non-JSON prefix and suffix.

I suggest you extract the JSON data as a new field and then run spath on this field:

yourbasesearch
| rex field=_raw "(?<json_data>\{.+\})"
| spath input=json_data

The regex above is defined very broadly. Your sample event is full of strange symbols. So you might want to improve the regular expression.

Ideally, you would index pure JSON data in Splunk and set the sourcetype to json. This way, the JSON data gets parsed automatically.

0 Karma

ips_mandar
Builder

thanks @whrg
it is working at search time..
also to work at indextime if I remove all strange symbols before and after json data then simple spath command also might work.
Can you please help me to remove all strange symbols before indexing so it can parse the json data at indextime

0 Karma

whrg
Motivator

Perhaps you could modify the script which produces the log files. Modify the script that it only produces pure JSON without these headers and footers.

If that's not feasible, check out this thread: Remove first part of string before creating a JSON source type.

So I would suggest you put something like this in your props.conf:

[source::/your/logfile]
SEDCMD-remove_header = s/^.*?\{/{/1
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

Ready to make your IT operations smarter and more efficient? Discover how to automate Splunk alerts with Red ...