<?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 extracting value from complex JSON in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497427#M194795</link>
    <description>&lt;P&gt;Hi, need help on how to extract dat from this JSON.&lt;BR /&gt;
i have used spath to extract a part of my JSON to get this data structure:&lt;BR /&gt;
{&lt;BR /&gt;
  &amp;lt;"app name1"&amp;gt;: {&lt;BR /&gt;
    "reason": "all ok",&lt;BR /&gt;
    "upstreams": 1,&lt;BR /&gt;
    "dialouts": {&lt;BR /&gt;
      "idle": 40,&lt;BR /&gt;
      "total": 40,&lt;BR /&gt;
      "connecting": 0&lt;BR /&gt;
    },&lt;BR /&gt;
    &lt;SOMETIME more="" data="https://community.splunk.com/"&gt;&lt;BR /&gt;
  },&lt;BR /&gt;
  &amp;lt;"app name2": {&lt;BR /&gt;
    "reason": "all ok",&lt;BR /&gt;
    "upstreams": 2,&lt;BR /&gt;
    "dialouts": {&lt;BR /&gt;
      "idle": 15,&lt;BR /&gt;
      "total": 15,&lt;BR /&gt;
      "connecting": 0&lt;BR /&gt;
    },&lt;BR /&gt;
    &lt;SOMETIME more="" data="https://community.splunk.com/"&gt;&lt;BR /&gt;
  },&lt;BR /&gt;
  &amp;lt;"app name3": {&lt;BR /&gt;
    "reason": "all ok",&lt;BR /&gt;
    "upstreams": 2,&lt;BR /&gt;
    "dialouts": {&lt;BR /&gt;
      "idle": 15,&lt;BR /&gt;
      "total": 15,&lt;BR /&gt;
      "connecting": 0&lt;BR /&gt;
    },&lt;BR /&gt;
    &lt;SOMETIME more="" data="https://community.splunk.com/"&gt;&lt;BR /&gt;
  },&lt;BR /&gt;
  .....&lt;BR /&gt;
}&lt;/SOMETIME&gt;&lt;/SOMETIME&gt;&lt;/SOMETIME&gt;&lt;/P&gt;

&lt;P&gt;what i want to do is to have a table to for each  i have the idle, total and connecting from "dialouts":&lt;BR /&gt;
how can i do that?&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2019 08:59:25 GMT</pubDate>
    <dc:creator>mcohen13</dc:creator>
    <dc:date>2019-10-03T08:59:25Z</dc:date>
    <item>
      <title>extracting value from complex JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497427#M194795</link>
      <description>&lt;P&gt;Hi, need help on how to extract dat from this JSON.&lt;BR /&gt;
i have used spath to extract a part of my JSON to get this data structure:&lt;BR /&gt;
{&lt;BR /&gt;
  &amp;lt;"app name1"&amp;gt;: {&lt;BR /&gt;
    "reason": "all ok",&lt;BR /&gt;
    "upstreams": 1,&lt;BR /&gt;
    "dialouts": {&lt;BR /&gt;
      "idle": 40,&lt;BR /&gt;
      "total": 40,&lt;BR /&gt;
      "connecting": 0&lt;BR /&gt;
    },&lt;BR /&gt;
    &lt;SOMETIME more="" data="https://community.splunk.com/"&gt;&lt;BR /&gt;
  },&lt;BR /&gt;
  &amp;lt;"app name2": {&lt;BR /&gt;
    "reason": "all ok",&lt;BR /&gt;
    "upstreams": 2,&lt;BR /&gt;
    "dialouts": {&lt;BR /&gt;
      "idle": 15,&lt;BR /&gt;
      "total": 15,&lt;BR /&gt;
      "connecting": 0&lt;BR /&gt;
    },&lt;BR /&gt;
    &lt;SOMETIME more="" data="https://community.splunk.com/"&gt;&lt;BR /&gt;
  },&lt;BR /&gt;
  &amp;lt;"app name3": {&lt;BR /&gt;
    "reason": "all ok",&lt;BR /&gt;
    "upstreams": 2,&lt;BR /&gt;
    "dialouts": {&lt;BR /&gt;
      "idle": 15,&lt;BR /&gt;
      "total": 15,&lt;BR /&gt;
      "connecting": 0&lt;BR /&gt;
    },&lt;BR /&gt;
    &lt;SOMETIME more="" data="https://community.splunk.com/"&gt;&lt;BR /&gt;
  },&lt;BR /&gt;
  .....&lt;BR /&gt;
}&lt;/SOMETIME&gt;&lt;/SOMETIME&gt;&lt;/SOMETIME&gt;&lt;/P&gt;

&lt;P&gt;what i want to do is to have a table to for each  i have the idle, total and connecting from "dialouts":&lt;BR /&gt;
how can i do that?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 08:59:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497427#M194795</guid>
      <dc:creator>mcohen13</dc:creator>
      <dc:date>2019-10-03T08:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: extracting value from complex JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497428#M194796</link>
      <description>&lt;P&gt;I think you can regex to extract 2 element: &lt;BR /&gt;
- &amp;lt;"app name2" =&amp;gt; save fields app_name &lt;BR /&gt;
- { "reason": "all ok", "upstreams": 2, "dialouts": { "idle": 15, "total": 15, "connecting": 0 }, } =&amp;gt; data_app_name&lt;/P&gt;

&lt;P&gt;after, use &lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;|spath  input=data_app_name&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;, will extract all data values in data_app_name.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:28:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497428#M194796</guid>
      <dc:creator>longnh26</dc:creator>
      <dc:date>2020-09-30T02:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: extracting value from complex JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497429#M194797</link>
      <description>&lt;P&gt;can you add the regex itself? not so strong in regex&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 11:09:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497429#M194797</guid>
      <dc:creator>mcohen13</dc:creator>
      <dc:date>2019-10-03T11:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: extracting value from complex JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497430#M194798</link>
      <description>&lt;P&gt;You can write 2 regex:&lt;BR /&gt;
1. extract app_name: &lt;A href="https://regex101.com/r/vU0fJI/1"&gt;https://regex101.com/r/vU0fJI/1&lt;/A&gt;&lt;BR /&gt;
2. extract data: &lt;A href="https://regex101.com/r/vU0fJI/3"&gt;https://regex101.com/r/vU0fJI/3&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I just thought of another way.&lt;BR /&gt;
Can remove characters . It's example, if wrong syntax, please fix it.&lt;BR /&gt;
| rex mode=sed "s/&amp;lt;//g"&lt;BR /&gt;
| rex mode=sed "s/&amp;gt;//g"&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 01:55:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497430#M194798</guid>
      <dc:creator>longnh26</dc:creator>
      <dc:date>2019-10-04T01:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: extracting value from complex JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497431#M194799</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{
\"app name1\": { \"reason\": \"all ok\", \"upstreams\": 1, \"dialouts\": { \"idle\": 40, \"total\": 40, \"connecting\": 0 }, },
\"app name2\": { \"reason\": \"all ok\", \"upstreams\": 2, \"dialouts\": { \"idle\": 15, \"total\": 15, \"connecting\": 0 }, },
\"app name3\": { \"reason\": \"all ok\", \"upstreams\": 2, \"dialouts\": { \"idle\": 15, \"total\": 15, \"connecting\": 0 }, }
}"
| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| rex field=_raw max_match=0 "(?ms).*?(?&amp;lt;event&amp;gt;\"app name.*?},\s*\})(?=[\r\n\s\",]+(?:\}|app name))"
| mvexpand event
| rename event AS _raw
| eval _raw = "{" . _raw . "}"
| rex "(?&amp;lt;app_name&amp;gt;app[^\"]+)"
| rex mode=sed "s/app name\d+/app/"
| spath
| rename app.* AS *
| table app_name dialouts.*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Oct 2019 17:13:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/extracting-value-from-complex-JSON/m-p/497431#M194799</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-10-05T17:13:37Z</dc:date>
    </item>
  </channel>
</rss>

