<?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: How to convert JSON array of Key/Value pairs to Column/Value? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381810#M68858</link>
    <description>&lt;P&gt;@mlevsh &lt;/P&gt;

&lt;P&gt;Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=YOUR_INDEX | rename tags{}.Key as Keys, tags{}.Value as Values | eval temp=mvzip(Keys,Values) | mvexpand temp | eval Key=mvindex(split(temp,","),0),Value=mvindex(split(temp,","),1) | table account_id Key Value | eval {Key} = Value | stats values(*) as * by account_id | fields - Key, Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My Sample Search:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval _raw="{\"account_id\": \"1234567890\",\"created_time\": \"2019-05-16T15:00:45.000Z\",\"region\": \"us-1\",\"tags\": [ {\"Key\": \"environment\",\"Value\": \"env1\" }, {\"Key\" :\"data_class\",\"Value\": \"Class1\"},{\"Key\": \"built_by\",\"Value\": \"group1\" },{\"Key\": \"description\",\"Value\": \"anything\" },{\"Key\":\"application_id\",\"Value\": \"abc\" }] }" | kv | rename tags{}.Key as Keys, tags{}.Value as Values | eval temp=mvzip(Keys,Values) | mvexpand temp | eval Key=mvindex(split(temp,","),0),Value=mvindex(split(temp,","),1) | table account_id Key Value | eval {Key} = Value | stats values(*) as * by account_id | fields - Key, Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Mon, 20 May 2019 05:58:02 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2019-05-20T05:58:02Z</dc:date>
    <item>
      <title>How to convert JSON array of Key/Value pairs to Column/Value?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381808#M68856</link>
      <description>&lt;P&gt;Lets say we have Json data in the following format ( using 2 events as an example)&lt;/P&gt;

&lt;P&gt;Event 1)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Time    Event 5/19/19 2:26:06.730 PM    
{ [-] 
   account_id: 1234567890 
   created_time: 2019-05-16T15:00:45.000Z 
   region: us-1
   tags: [ [-] 
     { [-] 
       Key: environment 
       Value: env1 
     } 
     { [-] 
       Key: data_class 
       Value: Class1 
     } 
     { [-] 
       Key: built_by 
       Value: group1
     } 
     { [-] 
       Key: description 
       Value: anything 
     } 
     { [-] 
       Key: application_id 
       Value: abc 
     } 
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Event 2:    &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;5/19/19 2:26:06.620 PM  
{ [-] 
   account_id: 1234567891 
   created_time: 2019-05-13T21:31:02.710Z 
   region: us-1 
   tags: [ [-] 
     { [-] 
       Key: environment 
       Value: env2 
     } 
     { [-] 
       Key: data_class 
       Value: Class1 
     } 
     { [-] 
       Key: built_by 
       Value: group1
     } 
     { [-] 
       Key: description 
       Value: anything 
     } 
     { [-] 
       Key: application_id 
       Value: def 
     } 
   ] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The objective to display it in the following format: each Key in Key/Value pair needs to be a Column header and each Value needs to belong to corresponding Header(Key) , for example the above data needs to be in the following format&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Environment       data_class      build_by      description      application_id
env1              Class1          group1      anything            abc
env2              Class2          group1      anything            def
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any ideas will be appreciated!&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2019 18:47:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381808#M68856</guid>
      <dc:creator>mlevsh</dc:creator>
      <dc:date>2019-05-19T18:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert JSON array of Key/Value pairs to Column/Value?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381809#M68857</link>
      <description>&lt;P&gt;Your payload is not pure JSON, but a mixed message of timestamp &amp;amp;&amp;amp; JSON&lt;BR /&gt;
So there are two steps&lt;BR /&gt;
1. Do at indextime for extracting timestamp and line breaker etc.&lt;BR /&gt;
2. Do at searchtime for pure JSON message using &lt;CODE&gt;REPORT-&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The link &lt;A href="https://answers.splunk.com/answers/117121/extract-json-data-within-the-logs-json-mixed-with.html"&gt;https://answers.splunk.com/answers/117121/extract-json-data-within-the-logs-json-mixed-with.html&lt;/A&gt; will explain you how to do it using props &amp;amp; transforms.&lt;/P&gt;

&lt;P&gt;Alternatively, if you Just wanted to do at Search time, you can use SPATH command. Feed the pure JSON into spath command &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/spath"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/spath&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2019 19:26:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381809#M68857</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2019-05-19T19:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert JSON array of Key/Value pairs to Column/Value?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381810#M68858</link>
      <description>&lt;P&gt;@mlevsh &lt;/P&gt;

&lt;P&gt;Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=YOUR_INDEX | rename tags{}.Key as Keys, tags{}.Value as Values | eval temp=mvzip(Keys,Values) | mvexpand temp | eval Key=mvindex(split(temp,","),0),Value=mvindex(split(temp,","),1) | table account_id Key Value | eval {Key} = Value | stats values(*) as * by account_id | fields - Key, Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;My Sample Search:&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval _raw="{\"account_id\": \"1234567890\",\"created_time\": \"2019-05-16T15:00:45.000Z\",\"region\": \"us-1\",\"tags\": [ {\"Key\": \"environment\",\"Value\": \"env1\" }, {\"Key\" :\"data_class\",\"Value\": \"Class1\"},{\"Key\": \"built_by\",\"Value\": \"group1\" },{\"Key\": \"description\",\"Value\": \"anything\" },{\"Key\":\"application_id\",\"Value\": \"abc\" }] }" | kv | rename tags{}.Key as Keys, tags{}.Value as Values | eval temp=mvzip(Keys,Values) | mvexpand temp | eval Key=mvindex(split(temp,","),0),Value=mvindex(split(temp,","),1) | table account_id Key Value | eval {Key} = Value | stats values(*) as * by account_id | fields - Key, Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 05:58:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381810#M68858</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-05-20T05:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert JSON array of Key/Value pairs to Column/Value?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381811#M68859</link>
      <description>&lt;P&gt;@koshyk,&lt;BR /&gt;
We are running Slunk Cloud and cannot easily make any modifications on Indexers or Search heads&lt;/P&gt;

&lt;P&gt;We did  tried to use spath command, but were not successful so far&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 16:09:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381811#M68859</guid>
      <dc:creator>mlevsh</dc:creator>
      <dc:date>2019-05-20T16:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert JSON array of Key/Value pairs to Column/Value?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381812#M68860</link>
      <description>&lt;P&gt;Sample query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"account_id\": \"1234567890\",\"created_time\": \"2019-05-16T15:00:45.000Z\",\"region\": \"us-1\",\"tags\": [ {\"Key\": \"environment\",\"Value\": \"env1\" }, {\"Key\" :\"data_class\",\"Value\": \"Class1\"},{\"Key\": \"built_by\",\"Value\": \"group1\" },{\"Key\": \"description\",\"Value\": \"anything\" },{\"Key\":\"application_id\",\"Value\": \"abc\" }] }" 
| spath
| eval _raw=mvzip('tags{}.Key','tags{}.Value',"=")
| kv
| fields - _* tags*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Recommend:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_search
| spath
| eval _raw=mvzip('tags{}.Key','tags{}.Value',"=")
| kv
| fields - _* tags*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Jan 2020 05:10:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-convert-JSON-array-of-Key-Value-pairs-to-Column-Value/m-p/381812#M68860</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-01-11T05:10:45Z</dc:date>
    </item>
  </channel>
</rss>

