Splunk Search

Evaluate json boolean value with if statement

itaigev
New Member

Hi all, I am trying to run this simple search:

SourceType=FooMonitoring |eval isSuccess=if(Test.TestIsSuccessful=="true","Yes","No") | table isSuccess Test.TestIsSuccessful

I am getting the following results: (can't post an image...)

isSuccess   Test.TestIsSuccessful
--------------------------------------
No          true
No          true
No          true
No          true
No          true
No          true
No          true

I am expecting all the isSuccess values to be "Yes" but no matter what I do the if expression does not evaluate to true. Tried different ways, tried removing the double quotes around the "true" part with no luck.

Note that the raw data is json, but I didn't encounter any problems with it so far and I don't know if it is related or not...

I am using splunk 6

Please help me figure out what am I doing wrong.
Thanks!

Tags (1)
0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

Unfortunately, the dot (.) in eval expression syntax means "string concatenate". JSON kv parsing creates variables with a dot in their name, e.g., Test.TestIsSuccessful. However, eval parses that as a concatenation of two variables, Test and TestIsSuccessful.

To get around this, quote the variable name with single-quotes, so that the dot is not interpreted as the concatenation operator:

... | eval isSuccess=if('Test.TestIsSuccessful'=="true","Yes","No") | ...

View solution in original post

gkanapathy
Splunk Employee
Splunk Employee

Unfortunately, the dot (.) in eval expression syntax means "string concatenate". JSON kv parsing creates variables with a dot in their name, e.g., Test.TestIsSuccessful. However, eval parses that as a concatenation of two variables, Test and TestIsSuccessful.

To get around this, quote the variable name with single-quotes, so that the dot is not interpreted as the concatenation operator:

... | eval isSuccess=if('Test.TestIsSuccessful'=="true","Yes","No") | ...
Get Updates on the Splunk Community!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...