<?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: JSON to table with multi-value fields. in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349641#M64161</link>
    <description>&lt;P&gt;The "event" that you liked in your OP is not actually a single event; it is 1828 events ("items").  If you put it in as a single event, then I can't help you.  If you put it in as multiple events broken on each "item" then we can work.  Which is it?&lt;/P&gt;</description>
    <pubDate>Thu, 03 Aug 2017 20:23:59 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2017-08-03T20:23:59Z</dc:date>
    <item>
      <title>JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349637#M64157</link>
      <description>&lt;P&gt;Hi, all.&lt;/P&gt;

&lt;P&gt;I have a REST input configured and ingesting long events in JSON format. A sample event can be looked &lt;A href="https://www.dropbox.com/s/rtetm9uqrru43sa/log-event.json?raw=1"&gt;here&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;Splunk created the fields, I have:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3310i63BF743545C9768F/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Some objects in the JSON file are multi-value, like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "error": 0,
    "data": {
        "totalItems": 1,
        "items": [
            {
                "status": "enabled",
                "pci": [
                    "10.2.7",
                    "10.6.1"
                ],
                "description": "Crontab entry changed.",
                "file": "0020-syslog_rules.xml",
                "level": 5,
                "path": "/var/ossec/ruleset/rules",
                "groups": [
                    "syslog",
                    "cron"
                ],
                "id": 2832,
                "details": {
                    "if_sid": "2830",
                    "match": "REPLACE"
                }
            }
        ]
    }
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Where for example, &lt;CODE&gt;groups&lt;/CODE&gt; and &lt;CODE&gt;pci&lt;/CODE&gt; objects have multiple values. I want to present a table with some columns including those columns (data.items{}.id as id, data.items{}.file as file, data.items{}.description as desc, data.items{}.groups{} as groups, data.items{}.pci{} as pci, data.items{}.level as level) with no look until now. In summary, i need.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Create a table with the fields mentioned.&lt;/LI&gt;
&lt;LI&gt;Include all the multi-value data inside their respective field on the table.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;By now, I am spending time with something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="wpi" sourcetype="wrules" | head 1 | spath | rename data.items{}.id as id, data.items{}.file as file, data.items{}.description as desc, data.items{}.groups{} as groups, data.items{}.pci{} as pci, data.items{}.level as level |eval x=mvzip(file,mvzip(desc,mvzip(groups,mvzip(pci,level)))) | table file,desc,groups,pci,level
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But in cases with multi-value, I only have the first element and not all.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/3311i69ACFDFE0BA3726B/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Please help me!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 03:22:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349637#M64157</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2017-08-03T03:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349638#M64158</link>
      <description>&lt;P&gt;@changux, you have only two fields &lt;CODE&gt;groups&lt;/CODE&gt; and &lt;CODE&gt;pci&lt;/CODE&gt;. Since other fields are single value value, if you stitch them together using &lt;CODE&gt;mvzip()&lt;/CODE&gt;, it will retain only one value from all the fields.&lt;/P&gt;

&lt;P&gt;Try the following run anywhere search using &lt;CODE&gt;mvzip()&lt;/CODE&gt; only on multi-valued fields and then &lt;CODE&gt;mvexpand&lt;/CODE&gt; command to convert them to single value, followed by &lt;CODE&gt;split()&lt;/CODE&gt;to get the values of &lt;CODE&gt;groups&lt;/CODE&gt; and &lt;CODE&gt;pci&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval jsonData = "
 {
     \"error\": 0,
     \"data\": {
         \"totalItems\": 1,
         \"items\": [
             {
                 \"status\": \"enabled\",
                 \"pci\": [
                     \"10.2.7\",
                     \"10.6.1\"
                 ],
                 \"description\": \"Crontab entry changed.\",
                 \"file\": \"0020-syslog_rules.xml\",
                 \"level\": 5,
                 \"path\": \"/var/ossec/ruleset/rules\",
                 \"groups\": [
                     \"syslog\",
                     \"cron\"
                 ],
                 \"id\": 2832,
                 \"details\": {
                     \"if_sid\": \"2830\",
                     \"match\": \"REPLACE\"
                 }
             }
         ]
     }
 }
"
| spath input=jsonData path="data.items{}.id" output=id
| spath input=jsonData path="data.items{}.file" output=file
| spath input=jsonData path="data.items{}.description" output=desc
| spath input=jsonData path="data.items{}.groups{}" output=groups
| spath input=jsonData path="data.items{}.pci{}" output=pci
| spath input=jsonData path="data.items{}.level" output=level
| eval MVFields=mvzip(groups,pci)
| mvexpand MVFields
| eval MVFields=split(MVFields,",")
| eval groups=mvindex(MVFields,0)
| eval pci=mvindex(MVFields,1)
| table id file desc groups pci level
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Commands until &lt;CODE&gt;spath&lt;/CODE&gt; are to mimic sample data and fields. You will require commands from &lt;CODE&gt;mvzip()&lt;/CODE&gt; onward.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 08:20:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349638#M64158</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-03T08:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349639#M64159</link>
      <description>&lt;P&gt;Thank you so much for your help. I ran:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="wapi" sourcetype="wrules" | head 1 | spath  path="data.items{}.id" output=dataid
 | spath path="data.items{}.file" output=file
 | spath path="data.items{}.description" output=desc
 | spath path="data.items{}.groups{}" output=groups
 | spath path="data.items{}.pci{}" output=pci
 | spath path="data.items{}.level" output=level
 | eval x=mvzip(groups,pci)
 | mvexpand x
 | eval x=split(x,",")
 | eval groups=mvindex(x,0)
 | eval pci=mvindex(x,1)
 | table dataid file desc groups pci level
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Without luck. Check result:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://www.dropbox.com/s/i4q81smfrkougje/Screen%20Shot%202017-08-03%20at%209.31.29%20AM.png?raw=1" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Any suggestion?  In the other hand, the search takes a long time to show the result.&lt;/P&gt;

&lt;P&gt;Thank you again, I appreciate your help.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 16:38:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349639#M64159</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2017-08-03T16:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349640#M64160</link>
      <description>&lt;P&gt;More comments:&lt;/P&gt;

&lt;P&gt;Without &lt;CODE&gt;pci&lt;/CODE&gt; and &lt;CODE&gt;groups&lt;/CODE&gt; fields, the table is correct:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="wapi" sourcetype="wrules" | head 1 | spath  path="data.items{}.id" output=dataid
 | spath path="data.items{}.file" output=file
 | spath path="data.items{}.description" output=desc
 | spath path="data.items{}.level" output=level
  | spath path="data.items{}.pci{}" output=pci
 | table dataid file desc level
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I try with &lt;CODE&gt;PCI&lt;/CODE&gt; or &lt;CODE&gt;groups&lt;/CODE&gt;, the values don't correspond to JSON value (multi valued fields). &lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 19:04:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349640#M64160</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2017-08-03T19:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349641#M64161</link>
      <description>&lt;P&gt;The "event" that you liked in your OP is not actually a single event; it is 1828 events ("items").  If you put it in as a single event, then I can't help you.  If you put it in as multiple events broken on each "item" then we can work.  Which is it?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 20:23:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349641#M64161</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-03T20:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349642#M64162</link>
      <description>&lt;P&gt;What is wrong with this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
 | eval jsonData = "
  {
      \"error\": 0,
      \"data\": {
          \"totalItems\": 1,
          \"items\": [
              {
                  \"status\": \"enabled\",
                  \"pci\": [
                      \"10.2.7\",
                      \"10.6.1\"
                  ],
                  \"description\": \"Crontab entry changed.\",
                  \"file\": \"0020-syslog_rules.xml\",
                  \"level\": 5,
                  \"path\": \"/var/ossec/ruleset/rules\",
                  \"groups\": [
                      \"syslog\",
                      \"cron\"
                  ],
                  \"id\": 2832,
                  \"details\": {
                      \"if_sid\": \"2830\",
                      \"match\": \"REPLACE\"
                  }
              }
          ]
      }
  }"

| rename COMMENT AS "Everything above generates sample data; everything below is your solution"

| spath input=jsonData path="data.items{}.id" output=id
| spath input=jsonData path="data.items{}.file" output=file
| spath input=jsonData path="data.items{}.description" output=desc
| spath input=jsonData path="data.items{}.groups{}" output=groups
| spath input=jsonData path="data.items{}.pci{}" output=pci
| spath input=jsonData path="data.items{}.level" output=level
| table id file desc groups pci level
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2017 20:28:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349642#M64162</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-08-03T20:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349643#M64163</link>
      <description>&lt;P&gt;With your example, works perfect, but, when I tried with my ingested data, doesn't work well.&lt;/P&gt;

&lt;P&gt;Sample &lt;A href="https://www.dropbox.com/s/rtetm9uqrru43sa/log-event.json?raw=1"&gt;event&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;My query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="wazuh_api"  sourcetype="wazuh_api_rules" | head 1 
 | spath input=_raw path="data.items{}.id" output=id
 | spath input=_raw path="data.items{}.file" output=file
 | spath input=_raw path="data.items{}.description" output=desc
 | spath input=_raw path="data.items{}.groups{}" output=groups
 | spath input=_raw path="data.items{}.pci{}" output=pci
 | spath input=_raw path="data.items{}.level" output=level
 | table id file desc groups pci level
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;A href="https://www.dropbox.com/s/836hue0gtzqt25v/Search%20_%20Splunk%206.6.pdf?raw=1"&gt;result&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 21:01:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349643#M64163</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2017-08-03T21:01:44Z</dc:date>
    </item>
    <item>
      <title>Re: JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349644#M64164</link>
      <description>&lt;P&gt;My propose is to have a table with correct &lt;CODE&gt;PCI&lt;/CODE&gt; and &lt;CODE&gt;group&lt;/CODE&gt; fields on each line, as in your example but with all records. Please help!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 21:06:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349644#M64164</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2017-08-03T21:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349645#M64165</link>
      <description>&lt;P&gt;Sounds great. How can I do?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2017 21:31:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349645#M64165</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2017-08-03T21:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349646#M64166</link>
      <description>&lt;P&gt;Is the number of results in pci and groups going to remain the same? Based on the question description "But in cases with multi-value, I only have the first element and not all.", I was thinking other fields are not multi-valued. But seems like they are.&lt;/P&gt;

&lt;P&gt;Let me convert my answer to comment and have a look at the sample data you have provided,&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 05:50:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349646#M64166</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-08-04T05:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: JSON to table with multi-value fields.</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349647#M64167</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2017 06:38:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/JSON-to-table-with-multi-value-fields/m-p/349647#M64167</guid>
      <dc:creator>changux</dc:creator>
      <dc:date>2017-08-04T06:38:42Z</dc:date>
    </item>
  </channel>
</rss>

