<?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: Json Query in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107795#M22658</link>
    <description>&lt;P&gt;In your json you once have a field "user", and once have a field "users". That can't be good.&lt;/P&gt;</description>
    <pubDate>Fri, 01 Feb 2013 22:51:24 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2013-02-01T22:51:24Z</dc:date>
    <item>
      <title>Json Query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107794#M22657</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
 I have the next json in splunk:&lt;/P&gt;

&lt;P&gt;{&lt;BR /&gt;&lt;BR /&gt;
  _data : {&lt;BR /&gt;&lt;BR /&gt;
    services : [&lt;BR /&gt;&lt;BR /&gt;
      {&lt;BR /&gt;&lt;BR /&gt;
        id : "FB00000",&lt;BR /&gt;&lt;BR /&gt;
        users : [&lt;BR /&gt;&lt;BR /&gt;
          100,&lt;BR /&gt;&lt;BR /&gt;
          122&lt;BR /&gt;&lt;BR /&gt;
        ]&lt;BR /&gt;&lt;BR /&gt;
      },&lt;BR /&gt;&lt;BR /&gt;
      {&lt;BR /&gt;&lt;BR /&gt;
        id : "FB11111",&lt;BR /&gt;&lt;BR /&gt;
        users : [&lt;BR /&gt;&lt;BR /&gt;
          404,&lt;BR /&gt;&lt;BR /&gt;
          797&lt;BR /&gt;&lt;BR /&gt;
        ]&lt;BR /&gt;&lt;BR /&gt;
      }&lt;BR /&gt;&lt;BR /&gt;
    ],&lt;BR /&gt;&lt;BR /&gt;
    socialNetwork : "FB"&lt;BR /&gt;&lt;BR /&gt;
  },&lt;BR /&gt;&lt;BR /&gt;
  _timestamp : "01-02-02013T01:00:04.582+0100",&lt;BR /&gt;&lt;BR /&gt;
  _type : "ServiceReport"&lt;BR /&gt;&lt;BR /&gt;
}&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;I would like to know the query to generate a table with the following format:&lt;/P&gt;

&lt;P&gt;ID               USER&lt;BR /&gt;&lt;BR /&gt;
FB00000          100&lt;BR /&gt;&lt;BR /&gt;
FB00000          122&lt;BR /&gt;&lt;BR /&gt;
FB11111          404&lt;BR /&gt;&lt;BR /&gt;
FB11111          797&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;I tried with: &lt;BR /&gt;
sourcetype="singleline_json" AND _type="ServiceReport" &lt;BR /&gt;&lt;BR /&gt;
| rename _data.services{}.users{} as USER  &lt;BR /&gt;&lt;BR /&gt;
| rename _data.services{}.id as ID  &lt;BR /&gt;&lt;BR /&gt;
| fields ID, USER&lt;BR /&gt;&lt;BR /&gt;
| mvexpand USER&lt;BR /&gt;&lt;BR /&gt;
| eval x=split(USER,",")&lt;BR /&gt;&lt;BR /&gt;
| eval USER = mvindex(x,0)&lt;BR /&gt;&lt;BR /&gt;
| table ID, USER&lt;BR /&gt;&lt;/P&gt;

&lt;P&gt;But it does not work.&lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2013 14:47:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107794#M22657</guid>
      <dc:creator>david_martinez</dc:creator>
      <dc:date>2013-02-01T14:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Json Query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107795#M22658</link>
      <description>&lt;P&gt;In your json you once have a field "user", and once have a field "users". That can't be good.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Feb 2013 22:51:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107795#M22658</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-02-01T22:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: Json Query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107796#M22659</link>
      <description>&lt;P&gt;It was a mistake for copy-paste, sorry -&amp;gt; fixed. Thanks for the advice&lt;/P&gt;</description>
      <pubDate>Sat, 02 Feb 2013 19:25:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107796#M22659</guid>
      <dc:creator>david_martinez</dc:creator>
      <dc:date>2013-02-02T19:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Json Query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107797#M22660</link>
      <description>&lt;P&gt;I see. Your names in front of the colons also lack quotation marks to be valid JSON.&lt;/P&gt;

&lt;P&gt;What exactly isn't working, what results are you getting?&lt;/P&gt;

&lt;P&gt;Edit: Once you fix that you can do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...  | spath path=_data.services{} output=services | mvexpand services | spath input=services | stats values(users{}) as users by id | mvexpand users
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to get this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    id      users
1   FB00000 100
2   FB00000 122
3   FB11111 404
4   FB11111 797
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Feb 2013 21:26:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107797#M22660</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-02-02T21:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: Json Query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107798#M22661</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="{\"_data\":{\"services\":[{\"id\":\"FB00000\",\"users\":[100,122]},{\"id\":\"FB11111\",\"users\":[404,797]}],\"socialNetwork\":\"FB\"},\"_timestamp\":\"01-02-02013T01:00:04.582+0100\",\"_type\":\"ServiceReport\"}"
| spath path=_data.services{} output=data
| kv
| rename data.services{}.* as * 
| stats count by data.socialNetwork timestamp type data
| spath input=data
| stats count values(*) as * by users{}
| rename users{} as users, data.socialNetwork as socialNetwork
| table id users socialNetwork timestamp type
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/98620/mvexpand-gives-mvexpand-output-will-be-truncated-due-to-excessive-memory-usage.html"&gt;mvexpand gives "mvexpand output will be truncated due to excessive memory usage&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Because of this kind of problem,&lt;BR /&gt;
 I thought of an expansion method that doesn't use &lt;CODE&gt;mvexpand&lt;/CODE&gt; and &lt;CODE&gt;mvzip&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;The point is that the field that becomes &lt;EM&gt;multivalue&lt;/EM&gt; is extracted once and expanded without using &lt;CODE&gt;mvexpand&lt;/CODE&gt; by &lt;CODE&gt;stats&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Dec 2019 07:00:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Json-Query/m-p/107798#M22661</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2019-12-07T07:00:20Z</dc:date>
    </item>
  </channel>
</rss>

