<?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: How to extract JSON arrays in Splunk in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630135#M218914</link>
    <description>&lt;P&gt;I have tried to extract but getting error&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=X "sts:ExternalId" | spath path= policyDocument output=policyDocument | fields - _raw | fields Version, Statement x | mvexpand x | spath input=x | rename Condition{} as Condition | mvexpand Condition | stats count as Count by Condition, Statement.&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;I&gt;&lt;SPAN&gt;Error in 'spath' command: You have not specified a path. Try using "path=mypath" as an argument to spath.&lt;/SPAN&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;I&gt;&lt;SPAN&gt;Can you suggest&amp;nbsp; the SPL ?&lt;/SPAN&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 08 Feb 2023 14:54:14 GMT</pubDate>
    <dc:creator>sahilmits</dc:creator>
    <dc:date>2023-02-08T14:54:14Z</dc:date>
    <item>
      <title>How to extract JSON arrays in Splunk?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630127#M218912</link>
      <description>&lt;P&gt;Here is the query i have and need to extract the&amp;nbsp;&lt;SPAN&gt;"sts:ExternalId"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;requestParameters: { [-]&lt;BR /&gt;policyDocument: {&lt;BR /&gt;"Version": "2012-10-17",&lt;BR /&gt;"Statement": [&lt;BR /&gt;{&lt;BR /&gt;"Sid": "AllowAssumeRoleForAnotherAccount",&lt;BR /&gt;"Effect": "Allow",&lt;BR /&gt;"Principal": {&lt;BR /&gt;"AWS": "arn:aws:iam::384280045676:role/jenkins-node-custom-efep"&lt;BR /&gt;},&lt;BR /&gt;"Action": "sts:AssumeRole",&lt;BR /&gt;"Condition": {&lt;BR /&gt;"StringEquals": {&lt;BR /&gt;"sts:ExternalId": "efep"&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;}&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 18:34:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630127#M218912</guid>
      <dc:creator>sahilmits</dc:creator>
      <dc:date>2023-02-08T18:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract JSON arrays in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630129#M218913</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/230488"&gt;@sahilmits&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you can use the spath command (&lt;A href="https://docs.splunk.com/Documentation/SplunkCloud/latest/SearchReference/Spath)" target="_blank"&gt;https://docs.splunk.com/Documentation/SplunkCloud/latest/SearchReference/Spath)&lt;/A&gt;&amp;nbsp;to extract all fields from a json format event.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2023 14:45:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630129#M218913</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2023-02-08T14:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract JSON arrays in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630135#M218914</link>
      <description>&lt;P&gt;I have tried to extract but getting error&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=X "sts:ExternalId" | spath path= policyDocument output=policyDocument | fields - _raw | fields Version, Statement x | mvexpand x | spath input=x | rename Condition{} as Condition | mvexpand Condition | stats count as Count by Condition, Statement.&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;I&gt;&lt;SPAN&gt;Error in 'spath' command: You have not specified a path. Try using "path=mypath" as an argument to spath.&lt;/SPAN&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;I&gt;&lt;SPAN&gt;Can you suggest&amp;nbsp; the SPL ?&lt;/SPAN&gt;&lt;/I&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 08 Feb 2023 14:54:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630135#M218914</guid>
      <dc:creator>sahilmits</dc:creator>
      <dc:date>2023-02-08T14:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract JSON arrays in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630159#M218924</link>
      <description>&lt;P&gt;Several pointers:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;SPL command options must not have space after =.&lt;/LI&gt;&lt;LI&gt;The actual path you are trying to reach is&amp;nbsp;&lt;SPAN&gt;requestParameters.policyDocument.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;If you use path to reach&amp;nbsp;requestParameters.policyDocument, that node will be extracted as raw JSON, therefore you need to perform spath again.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;SPAN&gt;Hence,&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=X "sts:ExternalId"
| spath path=requestParameters.policyDocument output=policyDocument
| spath input=policyDocument
| fields - _raw
| fields Version, Statement
| mvexpand Statement
| spath input=Statement
| rename Condition{} as Condition
| mvexpand Condition
| stats count as Count by Condition, Statement&lt;/LI-CODE&gt;&lt;P&gt;If you are only interested in requestParameters.policyDocument, you can bypass the first spath altogether,&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=X "sts:ExternalId"
| spath input=requestParameters.policyDocument
| fields - _raw
| fields Version, Statement
| mvexpand Statement
| spath input=Statement
| rename Condition{} as Condition
| mvexpand Condition
| stats count as Count by Condition, Statement&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 08 Feb 2023 18:26:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630159#M218924</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-08T18:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract JSON arrays in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630269#M218964</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp; &amp;nbsp;I have tried the Suggested SPL but it is not extracting the results&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=x "sts:ExternalId"&lt;BR /&gt;| spath input="requestParameters.policyDocument" path=Statement{}&lt;BR /&gt;| mvexpand Statement{}&lt;BR /&gt;| spath input="Statement{}"&lt;BR /&gt;| spath input="userIdentity"&lt;BR /&gt;| eval Permissions = mvappend('Action{}', Action), Resources = mvappend('Resource{}' ,Resource)&lt;BR /&gt;| table _time, StringEquals&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sahilmits_0-1675942728799.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23800i5E7A01E7B8BBD954/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sahilmits_0-1675942728799.png" alt="sahilmits_0-1675942728799.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sahilmits_1-1675942780149.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23801iF97815AA46094E3E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sahilmits_1-1675942780149.png" alt="sahilmits_1-1675942780149.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Feb 2023 11:40:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630269#M218964</guid>
      <dc:creator>sahilmits</dc:creator>
      <dc:date>2023-02-09T11:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract JSON arrays in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630428#M219025</link>
      <description>&lt;P&gt;Not sure what you are trying to do with userIdentity or Resource because your illustrated data don't contain any of these. &amp;nbsp;And the table doesn't include them, anyway. &amp;nbsp;So, I'll omit all that and just list Action and StringEquals nodes. Note: Your illustrated data indicates that Action will not be multivalue after mvexpand. &amp;nbsp;So, mvappend is not useful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=requestParameters.policyDocument.Statement{} OUTPUT=Statement
| mvexpand Statement
| spath input=Statement
| spath input=Statement path=Condition.StringEquals output=StringEquals
| table _time Action StringEquals&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Using your illustrated data (correcting for JSON syntax), I get&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;_time&lt;/TD&gt;&lt;TD&gt;Action&lt;/TD&gt;&lt;TD&gt;StringEquals&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2023-02-10 03:47:37&lt;/TD&gt;&lt;TD&gt;sts:AssumeRole&lt;/TD&gt;&lt;TD&gt;{ "sts:ExternalId": "efep" }&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 10 Feb 2023 11:52:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630428#M219025</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-10T11:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract JSON arrays in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630762#M219121</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp; Thanks for your response , Not sure why it is populate the results.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sahilmits_0-1676366295841.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23854i02E607722E7C57DF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sahilmits_0-1676366295841.png" alt="sahilmits_0-1676366295841.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2023 09:18:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630762#M219121</guid>
      <dc:creator>sahilmits</dc:creator>
      <dc:date>2023-02-14T09:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract JSON arrays in Splunk</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630907#M219161</link>
      <description>&lt;P&gt;It is best to go back to basics. &amp;nbsp;Do you get&amp;nbsp;requestParameters.policyDocument.Statement{} before doing any spath? &amp;nbsp;In fact, there are some loose ends in that data you illustrated.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Is it from a raw event?&lt;/LI&gt;&lt;LI&gt;The illustration is not properly quoted for conformance. &amp;nbsp;Can you illustrate an event in raw text? A conformant JSON would look like&lt;/LI&gt;&lt;/OL&gt;&lt;LI-CODE lang="markup"&gt;{
    "requestParameters": {
        "foo": "bar",
        "policyDocument": {
            "Version": "2012-10-17",
            "Statement": [
                {
                    "Sid": "AllowAssumeRoleForAnotherAccount",
                    "Effect": "Allow",
                    "Principal": {
                        "AWS": "arn:aws:iam::384280045676:role/jenkins-node-custom-efep"
                    },
                    "Action": "sts:AssumeRole",
                    "Condition": {
                        "StringEquals": {
                            "sts:ExternalId": "efep"
                        }
                    }
                }
            ]
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;(The above is what I used for emulation.)&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 05:21:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-JSON-arrays-in-Splunk/m-p/630907#M219161</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-02-15T05:21:06Z</dc:date>
    </item>
  </channel>
</rss>

