<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: I would like to make custom_fields a table column. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/I-would-like-to-make-custom-fields-a-table-column/m-p/342598#M164285</link>
    <description>&lt;P&gt;Hi&lt;BR /&gt;
this solution must be adapted to your real solution, especially &lt;CODE&gt;spath&lt;/CODE&gt; command configuration.&lt;BR /&gt;
Anyway, try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=mt_index sourcetype="json_no_timestamp" 
| spath 
| rename custom_fields{}.id AS id2 custom_fields{}.name AS name custom_fields{}.value AS value 
| rex "\{\"id\":\s+(?&amp;lt;id&amp;gt;\d+)," 
| eval 
     id=mvindex(id,0), 
     Date=mvindex(value,0), 
     Apply_Time=mvindex(value,1), 
     Actual_Time=mvindex(value,2), 
     created_on=mvindex(created_on,0), 
     updated_on=mvindex(updated_on,0)
| table id Date Apply_Time Actual_Time created_on updated_on
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
    <pubDate>Sun, 17 Dec 2017 06:58:37 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2017-12-17T06:58:37Z</dc:date>
    <item>
      <title>I would like to make custom_fields a table column.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/I-would-like-to-make-custom-fields-a-table-column/m-p/342597#M164284</link>
      <description>&lt;P&gt;We have imported Json data with the following custom_fields.&lt;/P&gt;

&lt;P&gt;{&lt;BR /&gt;
    "id": 100,&lt;BR /&gt;
    "custom_fields":&lt;BR /&gt;
        [{&lt;BR /&gt;
            "id": 1,&lt;BR /&gt;
            "name": "Date",&lt;BR /&gt;
            "value": "2017-12-15"&lt;BR /&gt;
        }, {&lt;BR /&gt;
            "id": 2,&lt;BR /&gt;
            "name": "Apply_Time",&lt;BR /&gt;
            "value": 1.5&lt;BR /&gt;
        }, {&lt;BR /&gt;
            "id": 3,&lt;BR /&gt;
            "name": "Actual_Time",&lt;BR /&gt;
            "value": 0&lt;BR /&gt;
        }],&lt;BR /&gt;
    "created_on": "2017-12-15",&lt;BR /&gt;
    "updated_on": "2017-12-15"&lt;BR /&gt;
}&lt;/P&gt;

&lt;P&gt;I want to make the value of custom_fields look like the table below.&lt;/P&gt;

&lt;P&gt;| id | Date | Apply_Time | Actual_Time | created_on | updated_on |&lt;BR /&gt;
| 100 | 2017-12-15 | 1.5 | 0 | 2017-12-15 | 2017-12-15 |&lt;/P&gt;

&lt;P&gt;I tried spath command etc, but I did not solve it.&lt;BR /&gt;
Thank you for your instruction.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:16:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/I-would-like-to-make-custom-fields-a-table-column/m-p/342597#M164284</guid>
      <dc:creator>TAmemiya</dc:creator>
      <dc:date>2020-09-29T17:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: I would like to make custom_fields a table column.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/I-would-like-to-make-custom-fields-a-table-column/m-p/342598#M164285</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
this solution must be adapted to your real solution, especially &lt;CODE&gt;spath&lt;/CODE&gt; command configuration.&lt;BR /&gt;
Anyway, try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=mt_index sourcetype="json_no_timestamp" 
| spath 
| rename custom_fields{}.id AS id2 custom_fields{}.name AS name custom_fields{}.value AS value 
| rex "\{\"id\":\s+(?&amp;lt;id&amp;gt;\d+)," 
| eval 
     id=mvindex(id,0), 
     Date=mvindex(value,0), 
     Apply_Time=mvindex(value,1), 
     Actual_Time=mvindex(value,2), 
     created_on=mvindex(created_on,0), 
     updated_on=mvindex(updated_on,0)
| table id Date Apply_Time Actual_Time created_on updated_on
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Bye.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Sun, 17 Dec 2017 06:58:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/I-would-like-to-make-custom-fields-a-table-column/m-p/342598#M164285</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2017-12-17T06:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: I would like to make custom_fields a table column.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/I-would-like-to-make-custom-fields-a-table-column/m-p/342599#M164286</link>
      <description>&lt;P&gt;@TAmemiya, Please try the following run anywhere search which mimics the sample data as per the question. The &lt;CODE&gt;| makeresults&lt;/CODE&gt; and &lt;CODE&gt;| eval _raw&lt;/CODE&gt; command before &lt;CODE&gt;| spath&lt;/CODE&gt; are used to create sample data, you can replace with your base search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{
\"id\": 100,
\"custom_fields\":
[{
\"id\": 1,
\"name\": \"Date\",
\"value\": \"2017-12-15\"
}, {
\"id\": 2,
\"name\": \"Apply_Time\",
\"value\": 1.5
}, {
\"id\": 3,
\"name\": \"Actual_Time\",
\"value\": 0
}],
\"created_on\": \"2017-12-15\",
\"updated_on\": \"2017-12-15\"
}"
| spath
| rename custom_fields{}.id as sub_id
| rename "custom_fields{}.*" as "*"
| eval name=mvappend(name,"id","created_on","updated_on")
| eval value=mvappend(value,id,created_on,updated_on)
| eval custom_fields=mvzip(name,value)
| mvexpand custom_fields
| eval custom_fields=split(custom_fields,",")
| eval name=mvindex(custom_fields,0)
| eval value=mvindex(custom_fields,1)
| table name value
| transpose header_field=name column_name=name
| fields - name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Refer to multivalue eval functions in Splunk Documentation: &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Dec 2017 07:21:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/I-would-like-to-make-custom-fields-a-table-column/m-p/342599#M164286</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-12-17T07:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: I would like to make custom_fields a table column.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/I-would-like-to-make-custom-fields-a-table-column/m-p/342600#M164287</link>
      <description>&lt;P&gt;Thank you for your reply, Mr. Niketnilay.&lt;BR /&gt;
I'll try it immediately.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Dec 2017 10:02:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/I-would-like-to-make-custom-fields-a-table-column/m-p/342600#M164287</guid>
      <dc:creator>TAmemiya</dc:creator>
      <dc:date>2017-12-27T10:02:36Z</dc:date>
    </item>
  </channel>
</rss>

