<?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: Extract a field from an escaped string inside a nested JSON in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/589949#M205402</link>
    <description>&lt;LI-CODE lang="markup"&gt;| rex "allowedSourceAddressPrefix\\\\\":\\\\\"(?&amp;lt;allowedSourceAddressPrefix&amp;gt;.*?)\\\\\""&lt;/LI-CODE&gt;</description>
    <pubDate>Mon, 21 Mar 2022 08:45:42 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2022-03-21T08:45:42Z</dc:date>
    <item>
      <title>How to extract a field from an escaped string inside a nested JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/589920#M205394</link>
      <description>&lt;P&gt;I'm looking for help in extracting "allowedSourceAddressPrefix" field/value from a JSON. This field is an escaped JSON string inside a nested JSON. Following is the JSON tree&lt;/P&gt;
&lt;P&gt;- properties (extracted by splunk)&lt;/P&gt;
&lt;P class="lia-indent-padding-left-30px"&gt;- /subscription/..../.../ (dynamic field)&lt;/P&gt;
&lt;P class="lia-indent-padding-left-60px"&gt;- ports (escaped json)&lt;/P&gt;
&lt;P class="lia-indent-padding-left-90px"&gt;- allowedSourceAddressPrefix (nested json)&lt;/P&gt;
&lt;P&gt;The allowedSourceAddressPrefix takes values of single ipaddress (or) multiple ip addresses (or) *.&lt;/P&gt;
&lt;P&gt;I have tried various rex patterns but failed in extracting the required field, Any help is appreciated. Following is the JSON that has the required field&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;properties: {
"User": "johndoe@contoso.com",
"/subscriptions/3483b2ca-02cf-4ff6-92af-99326c8fac7f/resourceGroups/apple-dev/providers/Microsoft.Compute/virtualMachines/gjappledev": "{\"id\":\"/subscriptions/3483b2ca-02cf-4ff6-92af-99326c8fac7f/resourceGroups/apple-dev/providers/Microsoft.Compute/virtualMachines/gjappledev\",\"ports\":[{\"number\":3389,\"allowedSourceAddressPrefix\":\"*\",\"endTimeUtc\":\"2022-03-21T1:50:39.1599446Z\"}]}",
"Justification": null
}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;TIA&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 17:41:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/589920#M205394</guid>
      <dc:creator>z0r0</dc:creator>
      <dc:date>2022-03-21T17:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a field from an escaped string inside a nested JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/589949#M205402</link>
      <description>&lt;LI-CODE lang="markup"&gt;| rex "allowedSourceAddressPrefix\\\\\":\\\\\"(?&amp;lt;allowedSourceAddressPrefix&amp;gt;.*?)\\\\\""&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 21 Mar 2022 08:45:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/589949#M205402</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-03-21T08:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a field from an escaped string inside a nested JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/590060#M205435</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;, but seems like I'm missing something to apply this when trying on actual data. The rex you've shared is working on makeresults(testing pattern). Can you pls correct me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying this command&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=test_ms* "operationName.localizedValue"="Initiate JIT Network Access Policy" "eventName.localizedValue"="JIT network access request initiate started"
| rex field=properties "allowedSourceAddressPrefix\\\":\\\"(?&amp;lt;allowedSourceAddressPrefix&amp;gt;.*?)\\\""
| table allowedSourceAddressPrefix&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And here's a sample data entry (actual raw data)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "channels": "Operation",
  "eventName": {
    "value": "JIT network access request initiate started",
    "localizedValue": "JIT network access request initiate started"
  },
  "eventSource": {
    "value": "Security",
    "localizedValue": "Security"
  },
  "id": "/subscriptions/3483b2ca-02cf-4ff6-92af-99326c8fac7f/resourceGroups/apple-dev/providers/Microsoft.Compute/virtualMachines/gjappledev/events/04xxxxab-5ecc-46b0-abfa-6aacb1f550ac/ticks/63783455299xxxxxx3",
  "level": "Informational",
  "resourceGroupName": "apple-dev",
  "resourceProviderName": {
    "value": "Microsoft.Compute",
    "localizedValue": "Microsoft.Compute"
  },
  "resourceUri": "/subscriptions/3483b2ca-02cf-4ff6-92af-99326c8fac7f/resourceGroups/apple-dev/providers/Microsoft.Compute/virtualMachines/gjappledev",
  "operationName": {
    "value": "Microsoft.Security/locations/jitNetworkAccessPolicies/initiate/action",
    "localizedValue": "Initiate JIT Network Access Policy"
  },
  "properties": {
    "User": "johndoe@contoso.com",
    "/subscriptions/3483b2ca-02cf-4ff6-92af-99326c8fac7f/resourceGroups/apple-dev/providers/Microsoft.Compute/virtualMachines/gjappledev": "{\"id\":\"/subscriptions/3483b2ca-02cf-4ff6-92af-99326c8fac7f/resourceGroups/apple-dev/providers/Microsoft.Compute/virtualMachines/gjappledev\",\"ports\":[{\"number\":3389,\"allowedSourceAddressPrefix\":\"*\",\"endTimeUtc\":\"2022-03-21T1:50:39.1599446Z\"}]}",
    "Justification": null
  },
  "status": {
    "value": "Accepted",
    "localizedValue": "Accepted"
  },
  "subStatus": {
    "value": null
  },
  "eventTimestamp": "2022-03-21T1:50:39.1599446Z",
  "submissionTimestamp": "2022-03-21T1:50:39.1599446Z",
  "subscriptionId": "3483b2ca-02cf-4ff6-92af-99326c8fac7f"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Again&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 18:33:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/590060#M205435</guid>
      <dc:creator>z0r0</dc:creator>
      <dc:date>2022-03-21T18:33:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a field from an escaped string inside a nested JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/590062#M205436</link>
      <description>&lt;P&gt;You don't have enough backslashes - you need 3 sets of 5 (like I showed in my example) - SPL requires an extra level of escaping for backslashes above what is required by regex101.com for example.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 18:41:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/590062#M205436</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-03-21T18:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a field from an escaped string inside a nested JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/590065#M205437</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;, just checked on regex101.com, the rex with three slashes works for the raw data i shared&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the rex string i gave in regex101.com is&amp;nbsp;&lt;BR /&gt;/allowedSourceAddressPrefix\\\":\\\"(?&amp;lt;allowedSourceAddressPrefix&amp;gt;.*?)\\\"/gm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for the raw data i shared and it was able to match and get the desired value.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 19:03:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/590065#M205437</guid>
      <dc:creator>z0r0</dc:creator>
      <dc:date>2022-03-21T19:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a field from an escaped string inside a nested JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/590070#M205438</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;, Oh, you meant more than regex101, still unable to get results with 5 slashes. Am I missing something when translating the command from makeresults example to the actual data(any formatting stuff)?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 19:44:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/590070#M205438</guid>
      <dc:creator>z0r0</dc:creator>
      <dc:date>2022-03-21T19:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Extract a field from an escaped string inside a nested JSON</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/590273#M205505</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;, the mistake I was doing is using | rex field=properties, your command worked for the actual data too. Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 16:49:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-field-from-an-escaped-string-inside-a-nested/m-p/590273#M205505</guid>
      <dc:creator>z0r0</dc:creator>
      <dc:date>2022-03-22T16:49:17Z</dc:date>
    </item>
  </channel>
</rss>

