<?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 How to extract a particular field from JSON event in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390085#M69819</link>
    <description>&lt;P&gt;Hi Guys ,&lt;/P&gt;

&lt;P&gt;Below is a sample JSON event that gets logged for each transaction .&lt;/P&gt;

&lt;P&gt;Requirement :In the attached snapshot, there is a field called &lt;STRONG&gt;latency_info&lt;/STRONG&gt;  under which I have &lt;STRONG&gt;task:proxy&lt;/STRONG&gt; . I need to get the &lt;STRONG&gt;started&lt;/STRONG&gt; time beside proxy , then substract that value from another field called &lt;EM&gt;time_to_serve_request&lt;/EM&gt; (not in the attached snapshot)  . Please let me know how to achieve this in in SPLUNK.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 22:02:13 GMT</pubDate>
    <dc:creator>vishnu10987</dc:creator>
    <dc:date>2020-09-29T22:02:13Z</dc:date>
    <item>
      <title>How to extract a particular field from JSON event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390085#M69819</link>
      <description>&lt;P&gt;Hi Guys ,&lt;/P&gt;

&lt;P&gt;Below is a sample JSON event that gets logged for each transaction .&lt;/P&gt;

&lt;P&gt;Requirement :In the attached snapshot, there is a field called &lt;STRONG&gt;latency_info&lt;/STRONG&gt;  under which I have &lt;STRONG&gt;task:proxy&lt;/STRONG&gt; . I need to get the &lt;STRONG&gt;started&lt;/STRONG&gt; time beside proxy , then substract that value from another field called &lt;EM&gt;time_to_serve_request&lt;/EM&gt; (not in the attached snapshot)  . Please let me know how to achieve this in in SPLUNK.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:02:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390085#M69819</guid>
      <dc:creator>vishnu10987</dc:creator>
      <dc:date>2020-09-29T22:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a particular field from JSON event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390086#M69820</link>
      <description>&lt;P&gt;My splunk query is below . Need to add on to the below splunk query :&lt;/P&gt;

&lt;P&gt;index="&lt;EM&gt;apic&lt;/EM&gt;" sourcetype=ApiEvent catalog_name=prod org_name=humana earliest=-24h &lt;BR /&gt;
| stats count as TxCount, count(eval(status_code="200 OK")) AS SuccessCount , count(eval(status_code!="200 OK")) as FailureCount , min(time_to_serve_request) as MinRT, avg(time_to_serve_request) as AvgRT , max(time_to_serve_request) as MaxRT ,p95(time_to_serve_request) as p95 , p99(time_to_serve_request) as p99, values(catalog_name) as "Catalog Name" by api_name &lt;BR /&gt;
|eval date=strftime(relative_time(now(), "-1d@d"), "%d-%b-%y")&lt;BR /&gt;
| rename api_name as "API Name" , date as Date&lt;BR /&gt;
| eval TxCount = tostring(TxCount,"commas") &lt;BR /&gt;
| eval SuccessCount = tostring(SuccessCount,"commas") &lt;BR /&gt;
| eval FailureCount = tostring(FailureCount,"commas") &lt;BR /&gt;
| eval MinRT = tostring(MinRT,"commas") &lt;BR /&gt;
| eval AvgRT=ceil(AvgRT) &lt;BR /&gt;
| eval AvgRT = tostring(AvgRT,"commas") &lt;BR /&gt;
| eval MaxRT = tostring(MaxRT,"commas") &lt;BR /&gt;
| eval p95 = tostring(p95,"commas")&lt;BR /&gt;&lt;BR /&gt;
| eval p99 = tostring(p99,"commas")&lt;BR /&gt;&lt;BR /&gt;
| rename TxCount as "Transactions Count" , SuccessCount as "Success Count" , FailureCount as "Failure Count" ,MinRT as "Minimum RoundTripTime (in ms)"  , AvgRT as "Average RoundTripTime (in ms)" ,MaxRT as "Maximum RoundTripTime (in ms)" ,p95 as "95thPercentile RoundTripTime (in ms)" ,p99 as "99thPercentile RoundTripTime (in ms)" &lt;BR /&gt;
| table Date,"API Name" ,"Catalog Name", "Transactions Count" ,"Success Count" , "Failure Count" , "Minimum RoundTripTime (in ms)" , "Average RoundTripTime (in ms)" , "Maximum RoundTripTime (in ms)" , "95thPercentile RoundTripTime (in ms)" , "99thPercentile RoundTripTime (in ms)"&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:02:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390086#M69820</guid>
      <dc:creator>vishnu10987</dc:creator>
      <dc:date>2020-09-29T22:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a particular field from JSON event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390087#M69821</link>
      <description>&lt;P&gt;There is no attached snapshot. Please copy-and-paste your example JSON event into a comment.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Nov 2018 15:02:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390087#M69821</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-11-11T15:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a particular field from JSON event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390088#M69822</link>
      <description>&lt;P&gt;{&lt;BR /&gt;
    "api_id": "5b592adee4b07bf1bfccef38",&lt;BR /&gt;
    "app_type": "PRODUCTION",&lt;BR /&gt;
    "bytes_received": 17,&lt;BR /&gt;
    "response_body": "",&lt;BR /&gt;
    "client_id": "4abbf92b-38dc-4561-ba7d-a0eff545048f",&lt;BR /&gt;
    "billing": {&lt;BR /&gt;
        "amount": 0,&lt;BR /&gt;
        "provider": "none",&lt;BR /&gt;
        "currency": "USD",&lt;BR /&gt;
        "model": "free",&lt;BR /&gt;
        "trial_period_days": 0&lt;BR /&gt;
    },&lt;BR /&gt;
    "datetime": "2018-11-12T02:15:40.513Z",&lt;BR /&gt;
    "time_to_serve_request": 281,&lt;BR /&gt;
    "uri_path": "/humana/prod/FormularyManagementServices/DrugList/AttributeValues",&lt;BR /&gt;
    "log_policy": "activity",&lt;BR /&gt;
    "endpoint_url": "N/A",&lt;BR /&gt;
    "product_id": "5b592adee4b07bf1bfccef39",&lt;BR /&gt;
    "host": "127.0.0.1",&lt;BR /&gt;
    "client_ip": "133.27.0.2",&lt;BR /&gt;
    "app_id": "5b312baee4b036bba7e4a948",&lt;BR /&gt;
    "client_geoip": {&lt;BR /&gt;
        "timezone": "Asia/Tokyo",&lt;BR /&gt;
        "ip": "133.27.0.2",&lt;BR /&gt;
        "latitude": 35.3261,&lt;BR /&gt;
        "continent_code": "AS",&lt;BR /&gt;
        "city_name": "Chigasaki",&lt;BR /&gt;
        "country_code2": "JP",&lt;BR /&gt;
        "country_name": "Japan",&lt;BR /&gt;
        "country_code3": "JP",&lt;BR /&gt;
        "region_name": "Kanagawa",&lt;BR /&gt;
        "location": [139.4039, 35.3261],&lt;BR /&gt;
        "postal_code": "253-0041",&lt;BR /&gt;
        "longitude": 139.4039,&lt;BR /&gt;
        "region_code": "14"&lt;BR /&gt;
    },&lt;BR /&gt;
    "request_protocol": "https",&lt;BR /&gt;
    "developer_org_id": "5a7102d4e4b0db876ea9228b",&lt;BR /&gt;
    "transaction_id": "465613565",&lt;BR /&gt;
    "immediate_client_ip": "133.27.0.2",&lt;BR /&gt;
    "product_name": "formularymanagementservice_product",&lt;BR /&gt;
    "plan_name": "formularymanagementservice_loadtest",&lt;BR /&gt;
    "product_title": "FormularyManagementService_Product",&lt;BR /&gt;
    "tags": [],&lt;BR /&gt;
    "catalog_id": "59403e01e4b0b0769e4fc3cc",&lt;BR /&gt;
    "space_name": ["product"],&lt;BR /&gt;
    "api_name": "formularymanagementservice_api",&lt;BR /&gt;
    "org_id": "59403e00e4b0b0769e4fc3c0",&lt;BR /&gt;
    "plan_version": "1.0",&lt;BR /&gt;
    "status_code": "200 OK",&lt;BR /&gt;
    "request_method": "POST",&lt;BR /&gt;
    "developer_org_name": "product-org",&lt;BR /&gt;
    "http_user_agent": "",&lt;BR /&gt;
    "@version": "1",&lt;BR /&gt;
    "response_http_headers": [],&lt;BR /&gt;
    "org_name": "humana",&lt;BR /&gt;
    "latency_info": [{&lt;BR /&gt;
        "task": "Start",&lt;BR /&gt;
        "started": 0&lt;BR /&gt;
    }, {&lt;BR /&gt;
        "task": "security-appID",&lt;BR /&gt;
        "started": 9&lt;BR /&gt;
    }, {&lt;BR /&gt;
        "task": "PlanRateLimits",&lt;BR /&gt;
        "started": 10&lt;BR /&gt;
    }, {&lt;BR /&gt;
        "task": "proxy",&lt;BR /&gt;
        "started": 11&lt;BR /&gt;
    }],&lt;BR /&gt;
    "headers": {&lt;BR /&gt;
        "http__ws_haprt_wlmversion": "-1",&lt;BR /&gt;
        "http_via": "1.1 AQAAAKrkLHM-",&lt;BR /&gt;
        "http_version": "HTTP/1.1",&lt;BR /&gt;
        "http_connection": "Keep-Alive",&lt;BR /&gt;
        "request_method": "POST",&lt;BR /&gt;
        "http_host": "localhost:9700",&lt;BR /&gt;
        "request_uri": "/_bulk",&lt;BR /&gt;
        "http_x_forwarded_server": "louapplpa1993.humana.com",&lt;BR /&gt;
        "content_type": "text/plain",&lt;BR /&gt;
        "http_x_global_transaction_id": "271f465d5be8e24c1bc0b32d",&lt;BR /&gt;
        "http_x_forwarded_host": "133.27.28.194:9443",&lt;BR /&gt;
        "http_x_forwarded_for": "133.27.0.238",&lt;BR /&gt;
        "request_path": "/_bulk",&lt;BR /&gt;
        "http_organization": "admin",&lt;BR /&gt;
        "http_x_client_ip": "127.0.0.1",&lt;BR /&gt;
        "content_length": "1897"&lt;BR /&gt;
    },&lt;BR /&gt;
    "catalog_name": "prod",&lt;BR /&gt;
    "product_version": "1.0",&lt;BR /&gt;
    "rateLimit": {&lt;BR /&gt;
        "rate-limit": {&lt;BR /&gt;
            "limit": "-1",&lt;BR /&gt;
            "count": "-1"&lt;BR /&gt;
        },&lt;BR /&gt;
        "LoadTestRate": {&lt;BR /&gt;
            "shared": "true",&lt;BR /&gt;
            "period": 86400,&lt;BR /&gt;
            "unit": "day",&lt;BR /&gt;
            "reject": "false",&lt;BR /&gt;
            "limit": 10000,&lt;BR /&gt;
            "count": 364,&lt;BR /&gt;
            "interval": 1&lt;BR /&gt;
        },&lt;BR /&gt;
        "rate-limit-1": {&lt;BR /&gt;
            "limit": "-1",&lt;BR /&gt;
            "count": "-1"&lt;BR /&gt;
        },&lt;BR /&gt;
        "rate-limit-2": {&lt;BR /&gt;
            "limit": "-1",&lt;BR /&gt;
            "count": "-1"&lt;BR /&gt;
        },&lt;BR /&gt;
        "per-minute": {&lt;BR /&gt;
            "limit": "-1",&lt;BR /&gt;
            "count": "-1"&lt;BR /&gt;
        }&lt;BR /&gt;
    },&lt;BR /&gt;
    "debug": [],&lt;BR /&gt;
    "api_version": "1.0",&lt;BR /&gt;
    "bytes_sent": 175014,&lt;BR /&gt;
    "app_name": "FormularyEnterprise_App",&lt;BR /&gt;
    "gateway_geoip": {&lt;BR /&gt;
        "timezone": "Asia/Tokyo",&lt;BR /&gt;
        "ip": "133.27.0.113",&lt;BR /&gt;
        "latitude": 35.3261,&lt;BR /&gt;
        "continent_code": "AS",&lt;BR /&gt;
        "city_name": "Chigasaki",&lt;BR /&gt;
        "country_code2": "JP",&lt;BR /&gt;
        "country_name": "Japan",&lt;BR /&gt;
        "country_code3": "JP",&lt;BR /&gt;
        "region_name": "Kanagawa",&lt;BR /&gt;
        "location": [139.4039, 35.3261],&lt;BR /&gt;
        "postal_code": "253-0041",&lt;BR /&gt;
        "longitude": 139.4039,&lt;BR /&gt;
        "region_code": "14"&lt;BR /&gt;
    },&lt;BR /&gt;
    "@timestamp": "2018-11-12T02:15:40.669Z",&lt;BR /&gt;
    "request_body": "",&lt;BR /&gt;
    "request_http_headers": [],&lt;BR /&gt;
    "resource_id": "formularymanagementservice_api:1.0:post:/DrugList/AttributeValues",&lt;BR /&gt;
    "gateway_ip": "133.27.0.113",&lt;BR /&gt;
    "space_id": ["59a0382be4b043d3d3a65e13"],&lt;BR /&gt;
    "plan_id": "formularymanagementservice_product:1.0:formularymanagementservice_loadtest",&lt;BR /&gt;
    "developer_org_title": "Product Org",&lt;BR /&gt;
    "query_string": []&lt;BR /&gt;
}&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:57:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390088#M69822</guid>
      <dc:creator>vishnu10987</dc:creator>
      <dc:date>2020-09-29T21:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a particular field from JSON event</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390089#M69823</link>
      <description>&lt;P&gt;One way would be to put something like this between the initial search and the stats command&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | spath output=started path=latency_info{}.started 
 | spath output=task path=latency_info{}.task 
 | eval mycount=mvcount(started)
 | eval myfan=mvrange(0,mycount)
 | mvexpand myfan
 | eval started=mvindex(started,myfan)
 | eval task=mvindex(task,myfan)
 | where task="proxy"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After the above code, there will be one record left for each individual record, and that record will have &lt;CODE&gt;task="proxy"&lt;/CODE&gt; and &lt;CODE&gt;started=&lt;/CODE&gt; whatever the number was, in this case , &lt;CODE&gt;11&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;If the JSON was already properly extracted as per &lt;CODE&gt;spath&lt;/CODE&gt;, then multivalue fields will exist called &lt;CODE&gt;latency_info{}.started&lt;/CODE&gt; and &lt;CODE&gt;latency_info{}.task&lt;/CODE&gt;, and it might be possible to collapse the above code into this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eval mycount=mvcount('latency_info{}.started')
 | eval myfan=mvrange(0,mycount)
 | mvexpand myfan
 | eval started=mvindex('latency_info{}.started',myfan)
 | eval task=mvindex('latency_info{}.task',myfan)
 | where task="proxy"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Run-anywhere demo code...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults |eval _raw="{\"api_id\": \"5b592adee4b07bf1bfccef38\",\"app_type\": \"PRODUCTION\",\"bytes_received\": 17,\"response_body\": \"\",\"client_id\": \"4abbf92b-38dc-4561-ba7d-a0eff545048f\",\"billing\": {\"amount\": 0,\"provider\": \"none\",\"currency\": \"USD\",\"model\": \"free\",\"trial_period_days\": 0},\"datetime\": \"2018-11-12T02:15:40.513Z\",\"time_to_serve_request\": 281,\"uri_path\": \"/humana/prod/FormularyManagementServices/DrugList/AttributeValues\",\"log_policy\": \"activity\",\"endpoint_url\": \"N/A\",\"product_id\": \"5b592adee4b07bf1bfccef39\",\"host\": \"127.0.0.1\",\"client_ip\": \"133.27.0.2\",\"app_id\": \"5b312baee4b036bba7e4a948\",\"client_geoip\": {\"timezone\": \"Asia/Tokyo\",\"ip\": \"133.27.0.2\",\"latitude\": 35.3261,\"continent_code\": \"AS\",\"city_name\": \"Chigasaki\",\"country_code2\": \"JP\",\"country_name\": \"Japan\",\"country_code3\": \"JP\",\"region_name\": \"Kanagawa\",\"location\": [139.4039, 35.3261],\"postal_code\": \"253-0041\",\"longitude\": 139.4039,\"region_code\": \"14\"},\"request_protocol\": \"https\",\"developer_org_id\": \"5a7102d4e4b0db876ea9228b\",\"transaction_id\": \"465613565\",\"immediate_client_ip\": \"133.27.0.2\",\"product_name\": \"formularymanagementservice_product\",\"plan_name\": \"formularymanagementservice_loadtest\",\"product_title\": \"FormularyManagementService_Product\",\"tags\": [],\"catalog_id\": \"59403e01e4b0b0769e4fc3cc\",\"space_name\": [\"product\"],\"api_name\": \"formularymanagementservice_api\",\"org_id\": \"59403e00e4b0b0769e4fc3c0\",\"plan_version\": \"1.0\",\"status_code\": \"200 OK\",\"request_method\": \"POST\",\"developer_org_name\": \"product-org\",\"http_user_agent\": \"\",\"@version\": \"1\",\"response_http_headers\": [],\"org_name\": \"humana\",\"latency_info\": [{\"task\": \"Start\",\"started\": 0}, {\"task\": \"security-appID\",\"started\": 9}, {\"task\": \"PlanRateLimits\",\"started\": 10}, {\"task\": \"proxy\",\"started\": 11}],\"headers\": {\"http__ws_haprt_wlmversion\": \"-1\",\"http_via\": \"1.1 AQAAAKrkLHM-\",\"http_version\": \"HTTP/1.1\",\"http_connection\": \"Keep-Alive\",\"request_method\": \"POST\",\"http_host\": \"localhost:9700\",\"request_uri\": \"/_bulk\",\"http_x_forwarded_server\": \"louapplpa1993.humana.com\",\"content_type\": \"text/plain\",\"http_x_global_transaction_id\": \"271f465d5be8e24c1bc0b32d\",\"http_x_forwarded_host\": \"133.27.28.194:9443\",\"http_x_forwarded_for\": \"133.27.0.238\",\"request_path\": \"/_bulk\",\"http_organization\": \"admin\",\"http_x_client_ip\": \"127.0.0.1\",\"content_length\": \"1897\"},\"catalog_name\": \"prod\",\"product_version\": \"1.0\",\"rateLimit\": {\"rate-limit\": {\"limit\": \"-1\",\"count\": \"-1\"},\"LoadTestRate\": {\"shared\": \"true\",\"period\": 86400,\"unit\": \"day\",\"reject\": \"false\",\"limit\": 10000,\"count\": 364,\"interval\": 1},\"rate-limit-1\": {\"limit\": \"-1\",\"count\": \"-1\"},\"rate-limit-2\": {\"limit\": \"-1\",\"count\": \"-1\"},\"per-minute\": {\"limit\": \"-1\",\"count\": \"-1\"}},\"debug\": [],\"api_version\": \"1.0\",\"bytes_sent\": 175014,\"app_name\": \"FormularyEnterprise_App\",\"gateway_geoip\": {\"timezone\": \"Asia/Tokyo\",\"ip\": \"133.27.0.113\",\"latitude\": 35.3261,\"continent_code\": \"AS\",\"city_name\": \"Chigasaki\",\"country_code2\": \"JP\",\"country_name\": \"Japan\",\"country_code3\": \"JP\",\"region_name\": \"Kanagawa\",\"location\": [139.4039, 35.3261],\"postal_code\": \"253-0041\",\"longitude\": 139.4039,\"region_code\": \"14\"},\"@timestamp\": \"2018-11-12T02:15:40.669Z\",\"request_body\": \"\",\"request_http_headers\": [],\"resource_id\": \"formularymanagementservice_api:1.0:post:/DrugList/AttributeValues\",\"gateway_ip\": \"133.27.0.113\",\"space_id\": [\"59a0382be4b043d3d3a65e13\"],\"plan_id\": \"formularymanagementservice_product:1.0:formularymanagementservice_loadtest\",\"developer_org_title\": \"Product Org\",\"query_string\": []}\""

 | rename COMMENT as "The above just enters your sample data"
 | spath output=started path=latency_info{}.started 
 | spath output=task path=latency_info{}.task 
 | eval mycount=mvcount(started)
 | eval myfan=mvrange(0,mycount)
 | mvexpand myfan
 | eval started=mvindex(started,myfan)
 | eval task=mvindex(task,myfan)
 | where task="proxy"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Nov 2018 04:42:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-extract-a-particular-field-from-JSON-event/m-p/390089#M69823</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-11-12T04:42:28Z</dc:date>
    </item>
  </channel>
</rss>

