<?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 Wrong JSON value extracted by query in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595413#M103994</link>
    <description>&lt;P&gt;I am running following query&amp;nbsp; where in the last I would like to fetch value of "Client" key from json and count all such clients. My query goes as follow:&lt;/P&gt;&lt;P&gt;QUERY | rex ".*\"Client\":\"(?&amp;lt;Client&amp;gt;.*)\"," | stats count byClient&lt;/P&gt;&lt;P&gt;The events in query will definitely&amp;nbsp; has json as the one of the key, but order of the key may change. This extraction of Client from json is not working and I am getting Client as null .What is the problem here.My event looks as follow&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Event type 1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;request-id : ABC  Executing following method: Class.RestClass ::: with values:

{
  "d1": "EU",
  "sn": "sn",
  "entityType": "USER",
  "email": "test@gmail.com",
  "id": [
    "123"
  ],
  "Client": "TEST",
  "time": "2020-01-01T01:01:01Z",
  "List": [
    {
      "Type": "Items1",
      "value": "-1",
      "match": "NO"
    }
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Event type 2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;request-id : 234  Execute something ::: with param-values:
{
  "d1": "JP",
  "sn": "sn",
  "type": "USER",
  "user": "test1@gmail.com",
  "id": [
    "123"
  ],
  "source": "S1",
  "Client": "test_client",
  "initiate": "init_Name",
  "mode": "Test",
  "t1": "",
  "t2": "",
  "auto": true,
  "list": [
    {
      "type": "type_count",
      "value": "-1",
      "creteria": "skip"
    }
  ]
}​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I correct my query to get the correct results:.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2022 13:42:38 GMT</pubDate>
    <dc:creator>user9025</dc:creator>
    <dc:date>2022-04-26T13:42:38Z</dc:date>
    <item>
      <title>Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595413#M103994</link>
      <description>&lt;P&gt;I am running following query&amp;nbsp; where in the last I would like to fetch value of "Client" key from json and count all such clients. My query goes as follow:&lt;/P&gt;&lt;P&gt;QUERY | rex ".*\"Client\":\"(?&amp;lt;Client&amp;gt;.*)\"," | stats count byClient&lt;/P&gt;&lt;P&gt;The events in query will definitely&amp;nbsp; has json as the one of the key, but order of the key may change. This extraction of Client from json is not working and I am getting Client as null .What is the problem here.My event looks as follow&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Event type 1:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;request-id : ABC  Executing following method: Class.RestClass ::: with values:

{
  "d1": "EU",
  "sn": "sn",
  "entityType": "USER",
  "email": "test@gmail.com",
  "id": [
    "123"
  ],
  "Client": "TEST",
  "time": "2020-01-01T01:01:01Z",
  "List": [
    {
      "Type": "Items1",
      "value": "-1",
      "match": "NO"
    }
  ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Event type 2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;request-id : 234  Execute something ::: with param-values:
{
  "d1": "JP",
  "sn": "sn",
  "type": "USER",
  "user": "test1@gmail.com",
  "id": [
    "123"
  ],
  "source": "S1",
  "Client": "test_client",
  "initiate": "init_Name",
  "mode": "Test",
  "t1": "",
  "t2": "",
  "auto": true,
  "list": [
    {
      "type": "type_count",
      "value": "-1",
      "creteria": "skip"
    }
  ]
}​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I correct my query to get the correct results:.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 13:42:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595413#M103994</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-04-26T13:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595420#M103995</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/243044"&gt;@user9025&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please try this?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;YOUR_SEARCH
| rex field=_raw "\"Client\":\s\"(?&amp;lt;Client&amp;gt;.+?)\""
| stats count by Client&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Sample Search :&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval _raw="{\"d1\": \"EU\",\"sn\": \"sn\",\"entityType\": \"USER\",\"email\": \"test@gmail.com\",\"id\": [\"123\"],\"Client\": \"TEST\",\"time\": \"2020-01-01T01:01:01Z\",\"List\": [{\"Type\": \"Items1\",\"value\": \"-1\",\"match\": \"NO\"}]}" 
| append 
    [| makeresults 
    | eval _raw="{\"d1\": \"JP\",\"sn\": \"sn\",\"type\": \"USER\",\"user\": \"test1@gmail.com\",\"id\": [\"123\"],\"source\": \"S1\",\"Client\": \"test_client\",\"initiate\": \"init_Name\",\"mode\": \"Test\",\"t1\": \"\",\"t2\": \"\",\"auto\": true,\"list\": [{\"type\": \"USER_DRAFTS_COUNT\",\"value\": \"-1\",\"creteria\": \"skip\"}]}"
        ] 
| rex field=_raw "\"Client\":\s\"(?&amp;lt;Client&amp;gt;.+?)\""
| stats count by Client&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-04-26 at 7.12.43 PM.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/19331i186CE7FAC0F5EDFC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2022-04-26 at 7.12.43 PM.png" alt="Screenshot 2022-04-26 at 7.12.43 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 13:42:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595420#M103995</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-04-26T13:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595423#M103996</link>
      <description>&lt;P&gt;The .* at the beginning is unnecessary - try delimiting Client by the next double quote "&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;QUERY | rex "\"Client\":\"(?&amp;lt;Client&amp;gt;[^\"]+)\"," | stats count byClient&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 13:48:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595423#M103996</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-04-26T13:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595435#M103999</link>
      <description>&lt;P&gt;thanks for the reply but it did not work .Same problem.Statistics is empty.My data is&amp;nbsp;&lt;/P&gt;&lt;P&gt;request-id : ABC Executing following method: Class.RestClass ::: with values:&amp;nbsp;&lt;/P&gt;&lt;P&gt;and then json follows this&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 15:22:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595435#M103999</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-04-26T15:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595436#M104000</link>
      <description>&lt;P&gt;Thanks for reply but it did not work. You have taken plain json only. Where I have some text info +json.&lt;/P&gt;&lt;P&gt;Example&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;request-id : ABC  Executing following method: Class.RestClass ::: with values:&lt;/LI-CODE&gt;&lt;P&gt;and then json as I mentioned.&lt;/P&gt;&lt;P&gt;Can you prepend this statement in you example and then try if it works?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 15:26:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595436#M104000</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-04-26T15:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595437#M104001</link>
      <description>&lt;P&gt;Try extracting the JSON and using spath&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;QUERY 
| rex "(?ms)(?&amp;lt;json&amp;gt;\{.*\})$"
| spath input=json Client 
| stats count by Client&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 26 Apr 2022 15:33:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595437#M104001</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-04-26T15:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595441#M104002</link>
      <description>&lt;P&gt;It works with your examples also when I have added those text before JSON part. Probably there has change something when you have copy paste those examples?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 15:50:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595441#M104002</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2022-04-26T15:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595456#M104004</link>
      <description>&lt;P&gt;I ran the query given as:&lt;/P&gt;&lt;P&gt;Query | rex "(?ms)(?&amp;lt;json&amp;gt;\{.*\})$" | table json&lt;/P&gt;&lt;P&gt;The json I am getting is as follow:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;{
  "timestamp": "2022-04-26T15:34:27.679Z",
  "logger_name": "c.a.s.c.c.r.s.RestServiceCommandExecutor",
  "thread_name": "http-exex-5",
  "level": "INFO",
  "serviceath": "LA",
  "processName": "LA",
  "message": "request-id : 123  Executing following method: Test.execute ::: with param-values: {\"DName\":\"EU\",\"service\":\"Test\",\"type\":\"USER\",\"key\":\"test@gmail.com\",\"Id\":[\"123\"],\"Client\":\"MY_TEST_CLIENT\",\"time\":\"2020-01-01T01:01:01Z\",\"list\":[{\"type\":\"COUNT\",\"value\":\"-1\",\"creteria\":\"SKIP\"}]},,",
  "requestId": "456",
  "x-correlation-id": "567",
  "trace_id": "987",
  "trace_flags": "09",
  "span_id": "123"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am interested in the message parameters,There is json after param-values.In that Json there is Client which I am trying to extract.Can you please check this?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 16:29:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595456#M104004</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-04-26T16:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595458#M104005</link>
      <description>&lt;P&gt;I got json from but it is giving lot of parameters and I am interested only in param-values in message .Following is result:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I ran the query given as:&lt;/P&gt;&lt;P&gt;Query | rex "(?ms)(?&amp;lt;json&amp;gt;\{.*\})$" | table json&lt;/P&gt;&lt;P&gt;The json I am getting is as follow:&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;{
  "timestamp": "2022-04-26T15:34:27.679Z",
  "logger_name": "c.a.s.c.c.r.s.RestServiceCommandExecutor",
  "thread_name": "http-exex-5",
  "level": "INFO",
  "serviceath": "LA",
  "processName": "LA",
  "message": "request-id : 123  Executing following method: Test.execute ::: with param-values: {\"DName\":\"EU\",\"service\":\"Test\",\"type\":\"USER\",\"key\":\"test@gmail.com\",\"Id\":[\"123\"],\"Client\":\"MY_TEST_CLIENT\",\"time\":\"2020-01-01T01:01:01Z\",\"list\":[{\"type\":\"COUNT\",\"value\":\"-1\",\"creteria\":\"SKIP\"}]},,",
  "requestId": "456",
  "x-correlation-id": "567",
  "trace_id": "987",
  "trace_flags": "09",
  "span_id": "123"
}&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 interested in the message parameters,There is json after param-values.In that Json there is Client which I am trying to extract.Can you please check this?&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 26 Apr 2022 16:31:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595458#M104005</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-04-26T16:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595459#M104006</link>
      <description>&lt;P&gt;If you see, the json i pasted in above comment, it has some weird double comma at then end.But this is what I have.Can I make it work.Cant I directly fetch client.?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 16:56:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595459#M104006</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-04-26T16:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595464#M104007</link>
      <description>&lt;LI-CODE lang="markup"&gt;QUERY 
| rex "(?ms)(?&amp;lt;json&amp;gt;\{.*\})$"
| spath input=json message
| rex field=message "(?&amp;lt;values&amp;gt;\{.*\})"
| spath input=values Client
| stats count by Client&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 26 Apr 2022 17:50:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595464#M104007</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-04-26T17:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595492#M104015</link>
      <description>&lt;P&gt;you are a saviour.thanks&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 22:55:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595492#M104015</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-04-26T22:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: Wrong JSON value extracted by query</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595493#M104016</link>
      <description>&lt;P&gt;The message is already coming as output from query, we just need to extract client from it.Can you try to run your answer against json i pasted above.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 23:01:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Wrong-JSON-value-extracted-by-query/m-p/595493#M104016</guid>
      <dc:creator>user9025</dc:creator>
      <dc:date>2022-04-26T23:01:49Z</dc:date>
    </item>
  </channel>
</rss>

