<?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 Splunk Create Fields from Field Values in Json log in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Create-Fields-from-Field-Values-in-Json-log/m-p/507284#M141853</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create new field values from my json log base on the values that appear under a particular field&lt;/P&gt;&lt;P&gt;So here is an example&lt;/P&gt;&lt;PRE&gt;{
   "widget": {
       "text": [ 
        {
           "data": "Click here",
           "size": 36
        },
       {
          "data": "Learn more",
          "size": 37
       },
       {
          "data": "Help",
          "size": 38
       },
       ]
   }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;So in my environment I currently have got widget{}.text{}.data as a field, however i would like to break it further and have&lt;/P&gt;&lt;P&gt;widget{}.text{}.data{}.ClickHere,&amp;nbsp;&lt;/P&gt;&lt;P&gt;widget{}.text{}.data{}.Help,&amp;nbsp;&lt;/P&gt;&lt;P&gt;widget{}.text{}.data{}.LearnMore as individual fields&lt;/P&gt;&lt;P&gt;I ask this because when we have thousands of logs and are looking for certain combinations, we have issues with filtering accurately, doing this will help us find the right combinations&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance will be greatly appreciated,&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jul 2020 17:45:50 GMT</pubDate>
    <dc:creator>ssjabid</dc:creator>
    <dc:date>2020-07-03T17:45:50Z</dc:date>
    <item>
      <title>Splunk Create Fields from Field Values in Json log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Create-Fields-from-Field-Values-in-Json-log/m-p/507284#M141853</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create new field values from my json log base on the values that appear under a particular field&lt;/P&gt;&lt;P&gt;So here is an example&lt;/P&gt;&lt;PRE&gt;{
   "widget": {
       "text": [ 
        {
           "data": "Click here",
           "size": 36
        },
       {
          "data": "Learn more",
          "size": 37
       },
       {
          "data": "Help",
          "size": 38
       },
       ]
   }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;So in my environment I currently have got widget{}.text{}.data as a field, however i would like to break it further and have&lt;/P&gt;&lt;P&gt;widget{}.text{}.data{}.ClickHere,&amp;nbsp;&lt;/P&gt;&lt;P&gt;widget{}.text{}.data{}.Help,&amp;nbsp;&lt;/P&gt;&lt;P&gt;widget{}.text{}.data{}.LearnMore as individual fields&lt;/P&gt;&lt;P&gt;I ask this because when we have thousands of logs and are looking for certain combinations, we have issues with filtering accurately, doing this will help us find the right combinations&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance will be greatly appreciated,&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 17:45:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Create-Fields-from-Field-Values-in-Json-log/m-p/507284#M141853</guid>
      <dc:creator>ssjabid</dc:creator>
      <dc:date>2020-07-03T17:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Create Fields from Field Values in Json log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Create-Fields-from-Field-Values-in-Json-log/m-p/507312#M141857</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{
   \"widget\": {
       \"text\": [ 
        {
           \"data\": \"Click here\",
           \"size\": 36
        },
       {
          \"data\": \"Learn more\",
          \"size\": 37
       },
       {
          \"data\": \"Help\",
          \"size\": 38
       },
       ]
   }
}"
| rex max_match=0 "(?ms)(?&amp;lt;jsons&amp;gt;{\s*\"data.*?})"
| stats count by jsons
| spath input=jsons
| eval {data}=size
| table "Click here" Help "Learn more"
| stats values(*) as *&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jul 2020 23:33:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Create-Fields-from-Field-Values-in-Json-log/m-p/507312#M141857</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-07-03T23:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Create Fields from Field Values in Json log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Create-Fields-from-Field-Values-in-Json-log/m-p/507340#M141860</link>
      <description>&lt;P&gt;Thank you for this, i will try it out on monday, it looks like it will work,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've heard online about {} creating a new set of fields from field values&lt;/P&gt;&lt;P&gt;what is the purpose of using the rex? is that just to capture data into a new field so that we can use spath on it? is this part absolutely necessary?&lt;/P&gt;&lt;P&gt;if you could explain exactly what {data}=size does that will help me understand its real use for further scenarios,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again, looking forward to trying this out!&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 13:06:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Create-Fields-from-Field-Values-in-Json-log/m-p/507340#M141860</guid>
      <dc:creator>ssjabid</dc:creator>
      <dc:date>2020-07-04T13:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Create Fields from Field Values in Json log</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Create-Fields-from-Field-Values-in-Json-log/m-p/507342#M141861</link>
      <description>&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw="{
   \"widget\": {
       \"text\": [ 
        {
           \"data\": \"Click here\",
           \"size\": 36
        },
       {
          \"data\": \"Learn more\",
          \"size\": 37
       },
       {
          \"data\": \"Help\",
          \"size\": 38
       },
       ]
   }
}"
| spath
| rename widget.text{}.* as *
| eval tmp=mvzip(data,size)
| stats count by tmp
| eval data=mvindex(split(tmp,","),0), size=mvindex(split(tmp,","),1)
| xyseries count data size
| fields - count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I like&amp;nbsp;&lt;STRONG&gt;rex&lt;/STRONG&gt;&amp;nbsp;to extract json array.(it's better to use &lt;STRONG&gt;mvzip&lt;/STRONG&gt;,I guess)&lt;/P&gt;&lt;P&gt;2. see&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Eval#Field_names" target="_blank" rel="noopener"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Eval#Field_names&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Jul 2020 13:57:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Create-Fields-from-Field-Values-in-Json-log/m-p/507342#M141861</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-07-04T13:57:17Z</dc:date>
    </item>
  </channel>
</rss>

