<?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 do I extract multiple key values from a double quoted JSON? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417095#M120028</link>
    <description>&lt;P&gt;you could also grab the json into a field and spath the results...&lt;/P&gt;

&lt;P&gt;like so: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="[INFO ] 17:01:43.572 : [main] o.a.k.c.Processor:process(103): response body from MYSERVICE : {\"uniqueNumber\": \"12345\", \"key-2\": \"value-2\", \"key-n\": \"value-n\", \"returnCode\": \"A12\"}" 
| rex field=_raw "response body from \w+ \: (?&amp;lt;json&amp;gt;\{.+\})$"
| spath input=json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;outputs: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;**_time**           
2018-10-04 12:48:35

**_raw**  
[INFO ] 17:01:43.572 : [main] o.a.k.c.Processor:process(103): response body from MYSERVICE : {"uniqueNumber": "12345", "key-2": "value-2", "key-n": "value-n", "returnCode": "A12"}

json
{"uniqueNumber": "12345", "key-2": "value-2", "key-n": "value-n", "returnCode": "A12"}  

**key-2**
value-2 

**key-n**
value-n 

**returnCode**
A12
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 04 Oct 2018 16:50:16 GMT</pubDate>
    <dc:creator>darrenfuller</dc:creator>
    <dc:date>2018-10-04T16:50:16Z</dc:date>
    <item>
      <title>How do I extract multiple key values from a double quoted JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417093#M120026</link>
      <description>&lt;P&gt;I have data in splunk as following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;log:     [INFO ] 17:01:43.572 : [main] o.a.k.c.Processor:process(103): response body from MYSERVICE : {"uniqueNumber": "12345", "key-2": "value-2",.. "key-n": "value-n", "returnCode": "A12"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and I am trying to extract key values pairs from double quoted json as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myquery "response body from MYSERVICE" |  rex "\"uniqueNumber\":\s\"(?&amp;lt;unumber&amp;gt;.*)\"" |  rex "\"returnCode\":\s\"(?&amp;lt;retcode&amp;gt;.*)\"" | table unumber retcode
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am expecting to populate the below table:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;+---------+---------+
| unumber | retcode |
+---------+---------+
|  123455 | A12     |
|  123456 | A10     |
|  123457 | A03     |
|  123458 | A01     |
+---------+---------+
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There is a space between key value pairs after the colon which I tried to match using  &lt;CODE&gt;\s&lt;/CODE&gt; but it generates an empty table.&lt;BR /&gt;
Any ideas ?&lt;/P&gt;

&lt;P&gt;PS: I am using Splunk Enterprise 7.1.2.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 16:08:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417093#M120026</guid>
      <dc:creator>baskarkrishnanc</dc:creator>
      <dc:date>2018-10-04T16:08:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract multiple key values from a double quoted JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417094#M120027</link>
      <description>&lt;P&gt;I tried this with small change in regex and it is working -&lt;BR /&gt;
Try below run anywhere search-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults |eval _raw=" log:     [INFO ] 17:01:43.572 : [main] o.a.k.c.Processor:process(103): response body from MYSERVICE : {\"uniqueNumber\": \"12345\", \"key-2\": \"value-2\",.. \"key-n\": \"value-n\", \"returnCode\": \"A12\"}"|  rex "\"uniqueNumber\":\s\"(?&amp;lt;unumber&amp;gt;[^\"]+)" |  rex "\"returnCode\":\s\"(?&amp;lt;retcode&amp;gt;[^\"]+)"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Oct 2018 16:36:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417094#M120027</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-10-04T16:36:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract multiple key values from a double quoted JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417095#M120028</link>
      <description>&lt;P&gt;you could also grab the json into a field and spath the results...&lt;/P&gt;

&lt;P&gt;like so: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="[INFO ] 17:01:43.572 : [main] o.a.k.c.Processor:process(103): response body from MYSERVICE : {\"uniqueNumber\": \"12345\", \"key-2\": \"value-2\", \"key-n\": \"value-n\", \"returnCode\": \"A12\"}" 
| rex field=_raw "response body from \w+ \: (?&amp;lt;json&amp;gt;\{.+\})$"
| spath input=json
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;outputs: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;**_time**           
2018-10-04 12:48:35

**_raw**  
[INFO ] 17:01:43.572 : [main] o.a.k.c.Processor:process(103): response body from MYSERVICE : {"uniqueNumber": "12345", "key-2": "value-2", "key-n": "value-n", "returnCode": "A12"}

json
{"uniqueNumber": "12345", "key-2": "value-2", "key-n": "value-n", "returnCode": "A12"}  

**key-2**
value-2 

**key-n**
value-n 

**returnCode**
A12
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Oct 2018 16:50:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417095#M120028</guid>
      <dc:creator>darrenfuller</dc:creator>
      <dc:date>2018-10-04T16:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract multiple key values from a double quoted JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417096#M120029</link>
      <description>&lt;P&gt;Thank you. This works as-is, but if I add this regex to my query, it is not working. I need to specify the index and search query to make it dynamic, such as &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myidx "MYNEWSERVICE" "response body from MYSERVICE" | rex "\"uniqueNumber\":\s\"(?&amp;lt;unumber&amp;gt;[^\"]+)" |  rex "\"returnCode\":\s\"(?&amp;lt;retcode&amp;gt;[^\"]+)" | table retcode unumber
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is that possible to skip eval as I need to use dynamic query results ?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 18:45:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417096#M120029</guid>
      <dc:creator>baskarkrishnanc</dc:creator>
      <dc:date>2018-10-04T18:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract multiple key values from a double quoted JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417097#M120030</link>
      <description>&lt;P&gt;I made some more changes in regex and it works now. I had to escape the escape backslash  as this is how Splunk showed as raw text like,&lt;CODE&gt;\"returnCode\": \"A01\"}\n","stream":"stdout","time":"2018-12-06T22:01:43.653111599Z"}&lt;/CODE&gt;. Not sure why Splunk escapes this way and deferring this to experts.&lt;/P&gt;

&lt;P&gt;Final query looks like&lt;BR /&gt;
    index=myidx "mysearchstring" "response body from MYSERVICE" | rex field=_raw "uniqueNumber[^\"]+\":\s*[^\"]+\"(?&lt;UNIQUENUMBER&gt;[^\\\"]+)" | rex field=_raw "returnCode[^\"]+\":\s*[^\"]+\"(?&lt;RETURN_CODE&gt;[^\\\"]+)" | table uniqueNumber Return_Code&lt;/RETURN_CODE&gt;&lt;/UNIQUENUMBER&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:33:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417097#M120030</guid>
      <dc:creator>baskarkrishnanc</dc:creator>
      <dc:date>2020-09-29T21:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract multiple key values from a double quoted JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417098#M120031</link>
      <description>&lt;P&gt;I tried to use spath but I had to make more regex changes so I went with regex. Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 20:47:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417098#M120031</guid>
      <dc:creator>baskarkrishnanc</dc:creator>
      <dc:date>2018-10-04T20:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract multiple key values from a double quoted JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417099#M120032</link>
      <description>&lt;P&gt;&lt;CODE&gt;|makeresults&lt;/CODE&gt; was generating command used just to test sample data ...you will use &lt;CODE&gt;rex&lt;/CODE&gt; command after &lt;CODE&gt;index=...&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 03:47:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417099#M120032</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-10-05T03:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do I extract multiple key values from a double quoted JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417100#M120033</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 15:47:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-extract-multiple-key-values-from-a-double-quoted-JSON/m-p/417100#M120033</guid>
      <dc:creator>baskarkrishnanc</dc:creator>
      <dc:date>2018-10-05T15:47:35Z</dc:date>
    </item>
  </channel>
</rss>

