Getting Data In

How to conditionally rename field in array of objects

stenvala
Engager

Hi,

I have query

| makeresults
| eval _raw="{\"name\": \"my name\", \"values\": [{\"rank\": 1, \"value\": \"\"}, {\"rank\": 2, \"value\": \"a\"}, {\"rank\": 3, \"value\": \"b\"}, {\"rank\": 4, \"value\": \"c\"}]}"
| spath
| rename values{}.rank as rank
| rename values{}.value as value
| table name, rank, value

Producing result

screenshot.PNG
Because in the first item of values, value is empty the values in the table are shifted one up and are not aligned with the rank. 

How could I conditionally update the value to, say, [empty] if that is empty string in the data?

Labels (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Fill in the empty values using the mvmap function.

| makeresults
| eval _raw="{\"name\": \"my name\", \"values\": [{\"rank\": 1, \"value\": \"\"}, {\"rank\": 2, \"value\": \"a\"}, {\"rank\": 3, \"value\": \"b\"}, {\"rank\": 4, \"value\": \"c\"}]}"
| spath
| rename values{}.rank as rank
| rename values{}.value as value
| eval value=mvmap(value,if(value="", "[empty]", value))
| table name, rank, value

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Fill in the empty values using the mvmap function.

| makeresults
| eval _raw="{\"name\": \"my name\", \"values\": [{\"rank\": 1, \"value\": \"\"}, {\"rank\": 2, \"value\": \"a\"}, {\"rank\": 3, \"value\": \"b\"}, {\"rank\": 4, \"value\": \"c\"}]}"
| spath
| rename values{}.rank as rank
| rename values{}.value as value
| eval value=mvmap(value,if(value="", "[empty]", value))
| table name, rank, value

 

---
If this reply helps you, Karma would be appreciated.
Get Updates on the Splunk Community!

Splunk App for Anomaly Detection End of Life Announcment

Q: What is happening to the Splunk App for Anomaly Detection?A: Splunk is officially announcing the ...

Aligning Observability Costs with Business Value: Practical Strategies

 Join us for an engaging Tech Talk on Aligning Observability Costs with Business Value: Practical ...

Mastering Data Pipelines: Unlocking Value with Splunk

 In today's AI-driven world, organizations must balance the challenges of managing the explosion of data with ...