<?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 write a search query for a hierachial JSON? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405610#M71982</link>
    <description>&lt;P&gt;Thanks @DalJeanis ! &lt;/P&gt;</description>
    <pubDate>Sat, 11 Aug 2018 05:46:30 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2018-08-11T05:46:30Z</dc:date>
    <item>
      <title>How do I write a search query for a hierachial JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405607#M71979</link>
      <description>&lt;P&gt;(I have no experience in Splunk searches)&lt;BR /&gt;
The question is simple: &lt;/P&gt;

&lt;P&gt;I have a JSON like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "name": "Testdata",
    "children": [
        {
            "name": "A",
            "children": [
            {
                "name": "A1",   
                "value": 436
            },
            {
                "name": "A2",
                "value": 546
            },
            {
                "name": "A3",
                "value": 223
            },
            {
                "name": "A4",
                "value": 132
            },
            {
                "name": "A5",
                "value": 115
            },
            {
                "name": "A6",
                "value": 96
            }]
        },
        {
            "name": "B",
            "children": [
            {
                "name": "B1",
                "value": 453
            },
            {
                "name": "B2",
                "value": 344
            },
            {
                "name": "B3",
                "value": 35
            },
            {
                "name": "B4",
                "value": 65
            },
            {
                "name": "B5",
                "value": 789
            },
            {
                "name": "B6",
                "value": 648
            },
            {
                "name": "B7",
                "value": 147
            }]
        }
      ]
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and I want a table like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;parent    |name   |value
A         |A1     | 436
A         |A2     | 546
...       |..     |..
B         |B1     |443
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(Sorry for the bad drawn table)&lt;/P&gt;

&lt;P&gt;Thanks for the answers!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 11:34:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405607#M71979</guid>
      <dc:creator>kjubie</dc:creator>
      <dc:date>2018-08-10T11:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a search query for a hierachial JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405608#M71980</link>
      <description>&lt;P&gt;Use &lt;CODE&gt;spath&lt;/CODE&gt; to parse the json. Here is an example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults |eval json="{
     \"name\": \"Testdata\",
     \"children\": [
         {
             \"name\": \"A\",
             \"children\": [
             {
                 \"name\": \"A1\",    
                 \"value\": 436
             },
             {
                 \"name\": \"A2\",
                 \"value\": 546
             },
             {
                 \"name\": \"A3\",
                 \"value\": 223
             },
             {
                 \"name\": \"A4\",
                 \"value\": 132
             },
             {
                 \"name\": \"A5\",
                 \"value\": 115
             },
             {
                 \"name\": \"A6\",
                 \"value\": 96
             }]
         },
         {
             \"name\": \"B\",
             \"children\": [
             {
                 \"name\": \"B1\",
                 \"value\": 453
             },
             {
                 \"name\": \"B2\",
                 \"value\": 344
             },
             {
                 \"name\": \"B3\",
                 \"value\": 35
             },
             {
                 \"name\": \"B4\",
                 \"value\": 65
             },
             {
                 \"name\": \"B5\",
                 \"value\": 789
             },
             {
                 \"name\": \"B6\",
                 \"value\": 648
             },
             {
                 \"name\": \"B7\",
                 \"value\": 147
             }]
         }
       ]
 }"
 |spath input=json|table children{}.name,children{}.children{}.name,children{}.children{}.value
 |rename children{}.children{}.name as grand_child_name,children{}.name as child_name,children{}.children{}.value as grand_child_value
 |eval zipped=mvzip(grand_child_name,grand_child_value)|table child_name,zipped|mvexpand zipped
 |mvexpand child_name|eval x=split(zipped,",")|eval grand_child_name=mvindex(x,0),grand_child_value=mvindex(x,1)
 |table child_name,grand_child_name,grand_child_value|eval match=substr(grand_child_name,0,1)|where child_name==match|fields - match
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Aug 2018 13:52:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405608#M71980</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-08-10T13:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a search query for a hierachial JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405609#M71981</link>
      <description>&lt;P&gt;Converted this to an answer because it answers the question with an excellent run-anywhere example.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Aug 2018 05:36:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405609#M71981</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-08-11T05:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a search query for a hierachial JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405610#M71982</link>
      <description>&lt;P&gt;Thanks @DalJeanis ! &lt;/P&gt;</description>
      <pubDate>Sat, 11 Aug 2018 05:46:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405610#M71982</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-08-11T05:46:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I write a search query for a hierachial JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405611#M71983</link>
      <description>&lt;P&gt;Thanks for your help! Works perfectly!&lt;/P&gt;</description>
      <pubDate>Mon, 13 Aug 2018 07:08:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-do-I-write-a-search-query-for-a-hierachial-JSON/m-p/405611#M71983</guid>
      <dc:creator>kjubie</dc:creator>
      <dc:date>2018-08-13T07:08:57Z</dc:date>
    </item>
  </channel>
</rss>

