<?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: Extract key value pairs from json file using regex in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607493#M211217</link>
    <description>&lt;P&gt;Thank you so much it is working.. Is it mandatory to use spath while using regex?&lt;/P&gt;&lt;P&gt;Also some of the keys have comma because of key is splitting, how can i avoid this? How to escape comma present in key?&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jul 2022 09:31:32 GMT</pubDate>
    <dc:creator>anooshac</dc:creator>
    <dc:date>2022-07-29T09:31:32Z</dc:date>
    <item>
      <title>How do I extract key value pairs from json file using regex?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607472#M211201</link>
      <description>&lt;P&gt;Hi all, I have a&amp;nbsp; sample json file like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{
"Project Name" : "abc",
"Project Group":"A",
"Unit":"B",
"groups_data":[{
"a":"32.064453125",
"b":"5.451171875",
"c":"0.3349609375",
"d":"0.181640625",
"e":"4.58203125",
"f":"81.1611328125"}]
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to plot a pie chart for the key value pairs present in the groups_data. I tried extracting the data using this query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;myindex sourcetype="_json"| rex field=_raw "\"group_data\":\[\{\"(?&amp;lt;component&amp;gt;[^/]*)\":"\"(?&amp;lt;Value&amp;gt;\d+)\"\}\]| eval tmp = mvzip(component,Value) |mvexpand tmp |eval component=mvindex(split(tmp,","),0) |eval Value=mvindex(split(tmp,","),1)|chart values(Value) by component&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not able to pie chart. It says tmp does not exist.Can anyone tell me is there anything wrong in the regex part? Something i missed anywhere?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 15:25:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607472#M211201</guid>
      <dc:creator>anooshac</dc:creator>
      <dc:date>2022-07-29T15:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract key value pairs from json file using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607477#M211205</link>
      <description>&lt;P&gt;Try extracting the groups_data (group_data?) with spath and then use max_match=0 for multiple extracts. Also, use a match string that matches your (example) data&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;myindex sourcetype="_json"
| spath output=groups_data groups_data{}
| rex field=groups_data max_match=0 "\"(?&amp;lt;component&amp;gt;[^\"]+)\":\"(?&amp;lt;Value&amp;gt;[\d\.]+)\""
| eval tmp = mvzip(component,Value) 
| mvexpand tmp 
| eval component=mvindex(split(tmp,","),0) 
| eval Value=mvindex(split(tmp,","),1)
| chart values(Value) by component&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 29 Jul 2022 07:32:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607477#M211205</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-07-29T07:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Extract key value pairs from json file using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607493#M211217</link>
      <description>&lt;P&gt;Thank you so much it is working.. Is it mandatory to use spath while using regex?&lt;/P&gt;&lt;P&gt;Also some of the keys have comma because of key is splitting, how can i avoid this? How to escape comma present in key?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 09:31:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607493#M211217</guid>
      <dc:creator>anooshac</dc:creator>
      <dc:date>2022-07-29T09:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: Extract key value pairs from json file using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607497#M211219</link>
      <description>&lt;P&gt;No, spath is not mandatory for use with rex, you could have extracted the groups_data in to a separate field with rex, then used another rex to extract the components and value pairs - the key here is the max_match=0 to apply the extract pattern multiple times.&lt;/P&gt;&lt;P&gt;Can you give an example of where this is failing (due to commas)?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 09:53:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607497#M211219</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-07-29T09:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Extract key value pairs from json file using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607692#M211306</link>
      <description>&lt;P&gt;Okay.. Thanks alot for the information.&lt;/P&gt;&lt;P&gt;There are some values like below.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"x,y":"32.064453125&lt;/LI-CODE&gt;&lt;P&gt;this will be extracted as x and y as key and values. How can i extract "x,y"&amp;nbsp; as a key?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 05:01:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607692#M211306</guid>
      <dc:creator>anooshac</dc:creator>
      <dc:date>2022-08-01T05:01:19Z</dc:date>
    </item>
    <item>
      <title>Re: Extract key value pairs from json file using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607693#M211307</link>
      <description>&lt;P&gt;Extract the pairs as tmp and split using the colon then trim the double-quotes&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;myindex sourcetype="_json"
| spath output=groups_data groups_data{}
| rex field=groups_data max_match=0 "(?&amp;lt;tmp&amp;gt;\"[^\"]+\":\"[\d\.]+\")"
| mvexpand tmp 
| eval component=trim(mvindex(split(tmp,":"),0),"\"")
| eval Value=trim(mvindex(split(tmp,":"),1),"\"")
| chart values(Value) by component&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 01 Aug 2022 05:12:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607693#M211307</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-08-01T05:12:16Z</dc:date>
    </item>
    <item>
      <title>Re: Extract key value pairs from json file using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607696#M211310</link>
      <description>&lt;P&gt;Thank you so much for the help! It is working fine now..&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 05:26:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607696#M211310</guid>
      <dc:creator>anooshac</dc:creator>
      <dc:date>2022-08-01T05:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Extract key value pairs from json file using regex</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607708#M211316</link>
      <description>&lt;P&gt;You could also extract component Value using regex.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval component=trim(mvindex(split(tmp,":"),0),"\"")
| eval Value=trim(mvindex(split(tmp,":"),1),"\"")&lt;/LI-CODE&gt;&lt;P&gt;=&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=tmp "\"(?&amp;lt;component&amp;gt;[^\"]+)\":\"(?&amp;lt;Value&amp;gt;[^\"]+)\""&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 07:54:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-key-value-pairs-from-json-file-using-regex/m-p/607708#M211316</guid>
      <dc:creator>jotne</dc:creator>
      <dc:date>2022-08-01T07:54:45Z</dc:date>
    </item>
  </channel>
</rss>

