<?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: Can you help me use the rex command to parse API's JSON? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-use-the-rex-command-to-parse-API-s-JSON/m-p/405391#M117187</link>
    <description>&lt;P&gt;Hi @gcescatto,&lt;/P&gt;

&lt;P&gt;There are 2 ways to achieve this. The first is to ingest JSON data with correct extractions before data indexing and another way is to achieve this via search query.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;To achieve this with correct field extractions before data indexing.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Here you can assign below configuration on a universal forwarder and then restart Splunk on universal forwarder.&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[yoursourcetype]
INDEXED_EXTRACTIONS = JSON
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;UL&gt;
&lt;LI&gt;If you do not want to change any configuration on universal forwarder, and you don't have too much data, then you can achieve it via search query. (Why I am saying "not too much data" because search query will generate extra load to do parsing at search time if you have more data rather; I prefer correct field extraction before data indexing)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Below is search query to parse correct data&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt; | spath input=_raw | rename {}.* AS *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Above query will extract many fields like &lt;CODE&gt;Eqpt Class Description&lt;/CODE&gt; , &lt;CODE&gt;Eqpt Criticality&lt;/CODE&gt; etc.&lt;/P&gt;

&lt;P&gt;Here is a run anywhere search to test on any Splunk instance.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="[
   {
     \"Eqpt Class Description\": null,
     \"Eqpt Criticality\": \"D\",
     \"Eqpt Criticality Desc\": \"Non Essential\",
     \"Eqpt Description\": null,
     \"Eqpt Type Description\": \"Instrumentation\",
     \"Maint Plant Caption\": null,
     \"Maint Plant Filter Code\": null,
     \"Maint Plant ID\": null
   },
   {
     \"Eqpt Class Description\": null,
     \"Eqpt Criticality\": \"D\",
     \"Eqpt Criticality Desc\": \"Non Essential\",
     \"Eqpt Description\": null,
     \"Eqpt Type Description\": \"Instrumentation\",
     \"Maint Plant Caption\": null,
     \"Maint Plant Filter Code\": null,
     \"Maint Plant ID\": null
   },
   {
     \"Eqpt Class Description\": null,
     \"Eqpt Criticality\": \"D\",
     \"Eqpt Criticality Desc\": \"Non Essential\",
     \"Eqpt Description\": null,
     \"Eqpt Type Description\": \"Instrumentation\",
     \"Maint Plant Caption\": null,
     \"Maint Plant Filter Code\": null,
     \"Maint Plant ID\": null
   }
 ]" 
 | spath input=_raw
 | rename {}.* AS *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 03 Oct 2018 08:33:55 GMT</pubDate>
    <dc:creator>harsmarvania57</dc:creator>
    <dc:date>2018-10-03T08:33:55Z</dc:date>
    <item>
      <title>Can you help me use the rex command to parse API's JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-use-the-rex-command-to-parse-API-s-JSON/m-p/405390#M117186</link>
      <description>&lt;P&gt;I have the following JSON, but I'm not really familiar with Splunk's &lt;CODE&gt;rex&lt;/CODE&gt; function.&lt;BR /&gt;
I tried this command without success: &lt;STRONG&gt;| rex "(?{[^}]+})" | mvexpand json_field | spath input=json_field&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[
  {
    "Eqpt Class Description": null,
    "Eqpt Criticality": "D",
    "Eqpt Criticality Desc": "Non Essential",
    "Eqpt Description": null,
    "Eqpt Type Description": "Instrumentation",
    "Maint Plant Caption": null,
    "Maint Plant Filter Code": null,
    "Maint Plant ID": null
  },
  {
    "Eqpt Class Description": null,
    "Eqpt Criticality": "D",
    "Eqpt Criticality Desc": "Non Essential",
    "Eqpt Description": null,
    "Eqpt Type Description": "Instrumentation",
    "Maint Plant Caption": null,
    "Maint Plant Filter Code": null,
    "Maint Plant ID": null
  },
  {
    "Eqpt Class Description": null,
    "Eqpt Criticality": "D",
    "Eqpt Criticality Desc": "Non Essential",
    "Eqpt Description": null,
    "Eqpt Type Description": "Instrumentation",
    "Maint Plant Caption": null,
    "Maint Plant Filter Code": null,
    "Maint Plant ID": null
  }
]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/256119-image001-1.jpg" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;For me to be able to build a dashboard with it, I need that to be displayed similar as in:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/256121-image002.jpg" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Could someone please help me to parse this on "&lt;STRONG&gt;}, {&lt;/STRONG&gt;"?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:29:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-use-the-rex-command-to-parse-API-s-JSON/m-p/405390#M117186</guid>
      <dc:creator>gcescatto</dc:creator>
      <dc:date>2020-09-29T21:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me use the rex command to parse API's JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-use-the-rex-command-to-parse-API-s-JSON/m-p/405391#M117187</link>
      <description>&lt;P&gt;Hi @gcescatto,&lt;/P&gt;

&lt;P&gt;There are 2 ways to achieve this. The first is to ingest JSON data with correct extractions before data indexing and another way is to achieve this via search query.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;To achieve this with correct field extractions before data indexing.&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Here you can assign below configuration on a universal forwarder and then restart Splunk on universal forwarder.&lt;/P&gt;

&lt;P&gt;props.conf&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[yoursourcetype]
INDEXED_EXTRACTIONS = JSON
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;UL&gt;
&lt;LI&gt;If you do not want to change any configuration on universal forwarder, and you don't have too much data, then you can achieve it via search query. (Why I am saying "not too much data" because search query will generate extra load to do parsing at search time if you have more data rather; I prefer correct field extraction before data indexing)&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;Below is search query to parse correct data&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt; | spath input=_raw | rename {}.* AS *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Above query will extract many fields like &lt;CODE&gt;Eqpt Class Description&lt;/CODE&gt; , &lt;CODE&gt;Eqpt Criticality&lt;/CODE&gt; etc.&lt;/P&gt;

&lt;P&gt;Here is a run anywhere search to test on any Splunk instance.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="[
   {
     \"Eqpt Class Description\": null,
     \"Eqpt Criticality\": \"D\",
     \"Eqpt Criticality Desc\": \"Non Essential\",
     \"Eqpt Description\": null,
     \"Eqpt Type Description\": \"Instrumentation\",
     \"Maint Plant Caption\": null,
     \"Maint Plant Filter Code\": null,
     \"Maint Plant ID\": null
   },
   {
     \"Eqpt Class Description\": null,
     \"Eqpt Criticality\": \"D\",
     \"Eqpt Criticality Desc\": \"Non Essential\",
     \"Eqpt Description\": null,
     \"Eqpt Type Description\": \"Instrumentation\",
     \"Maint Plant Caption\": null,
     \"Maint Plant Filter Code\": null,
     \"Maint Plant ID\": null
   },
   {
     \"Eqpt Class Description\": null,
     \"Eqpt Criticality\": \"D\",
     \"Eqpt Criticality Desc\": \"Non Essential\",
     \"Eqpt Description\": null,
     \"Eqpt Type Description\": \"Instrumentation\",
     \"Maint Plant Caption\": null,
     \"Maint Plant Filter Code\": null,
     \"Maint Plant ID\": null
   }
 ]" 
 | spath input=_raw
 | rename {}.* AS *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Oct 2018 08:33:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-use-the-rex-command-to-parse-API-s-JSON/m-p/405391#M117187</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-10-03T08:33:55Z</dc:date>
    </item>
  </channel>
</rss>

