<?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 multiple JSON fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647342#M224053</link>
    <description>&lt;P&gt;First, how accurate is the representation in that data illustration? &amp;nbsp;The sample contains an extraneous comma after alternateId, rendering the blob invalid as JSON. &amp;nbsp;If that is a problem, you need to bring that to your developers.&lt;/P&gt;&lt;P&gt;If I assume that the original data is valid, notice that target node is an array. &amp;nbsp;So, you will need to handle multiple entries in that entity. &amp;nbsp;In SPL, an array is flattened with an suffix "{}". &amp;nbsp;Usually you do not need JSON_EXTRACT in props.conf if the raw event is valide JSON; Splunk will automatically extract for you. &amp;nbsp;As a result, you should see flattened fields such as actor.*, target{}.*, and uuid. &amp;nbsp;To get individual objects in target{}, meanwhile, you should extract target{}, then split multivalues first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=target{}
| mvexpand target{}
| spath input=target{}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This should give you something like&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;alternateId&lt;/TD&gt;&lt;TD&gt;detailEntry&lt;/TD&gt;&lt;TD&gt;displayName&lt;/TD&gt;&lt;TD&gt;type&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;jane.doe@example.com&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;TD&gt;Doe, Jane&lt;/TD&gt;&lt;TD&gt;User&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;unknown&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;TD&gt;Good Employees&lt;/TD&gt;&lt;TD&gt;UserGroup&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is an emulation of your illustrated data with that syntax correction. &amp;nbsp;You can play with it and compare with your actual data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw = "{
    \"actor\": {
        \"type\": \"User\",
        \"alternateId\": \"john.smith@example.com\"
    },
    \"target\": [
        {
            \"type\": \"User\",
            \"alternateId\": \"jane.doe@example.com\",
            \"displayName\": \"Doe, Jane\",
            \"detailEntry\": null
        },
        {
            \"type\": \"UserGroup\",
            \"alternateId\": \"unknown\",
            \"displayName\": \"Good Employees\",
            \"detailEntry\": null
        }
    ],
    \"uuid\":\"58dd3885-0c4a-11ee-9843-938af4d00f2c\"
}"
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jun 2023 16:49:40 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2023-06-16T16:49:40Z</dc:date>
    <item>
      <title>Extract multiple JSON fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647335#M224050</link>
      <description>&lt;P&gt;I am trying to create a table whereby two of the values are within a JSON array. The data in each array entry is based on the "type" field. I can't seem to figure out how to extract the proper json using json_extract or spath, so I assume I'm going in the wrong direction. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;I can't figure out how to say 'Extract the value from displayName for the array entry where a specific key/value pair match my criteria'&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;P&gt;Example Data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "actor": {
        "type": "User",
        "alternateId": "john.smith@example.com"
    },
    "target": [
        {
            "type": "User",
            "alternateId": "jane.doe@example.com",
            "displayName": "Doe, Jane",
            "detailEntry": null
        },
        {
            "type": "UserGroup",
            "alternateId": "unknown",
            "displayName": "Good Employees",
            "detailEntry": null
        }
    ],
    "uuid":"58dd3885-0c4a-11ee-9843-938af4d00f2c"
}&lt;/LI-CODE&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;P&gt;Preferred Output&lt;/P&gt;&lt;TABLE border="1" width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;Actor&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;Group&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;User&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;john.smith@example.com&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;Good Employees&lt;/TD&gt;&lt;TD width="33.333333333333336%" height="25px"&gt;jane.doe@example.com&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 17:42:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647335#M224050</guid>
      <dc:creator>srcno</dc:creator>
      <dc:date>2023-06-16T17:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Extract multiple JSON fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647341#M224052</link>
      <description>&lt;LI-CODE lang="markup"&gt;| spath actor.alternateId output=Actor
| spath target{} output=target
| eval User=mvindex(target,0)
| spath input=User path=alternateId output=User
| eval Group=mvindex(target,1)
| spath input=Group path=displayName output=Group
| table Actor Group User&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Jun 2023 16:35:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647341#M224052</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-06-16T16:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extract multiple JSON fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647342#M224053</link>
      <description>&lt;P&gt;First, how accurate is the representation in that data illustration? &amp;nbsp;The sample contains an extraneous comma after alternateId, rendering the blob invalid as JSON. &amp;nbsp;If that is a problem, you need to bring that to your developers.&lt;/P&gt;&lt;P&gt;If I assume that the original data is valid, notice that target node is an array. &amp;nbsp;So, you will need to handle multiple entries in that entity. &amp;nbsp;In SPL, an array is flattened with an suffix "{}". &amp;nbsp;Usually you do not need JSON_EXTRACT in props.conf if the raw event is valide JSON; Splunk will automatically extract for you. &amp;nbsp;As a result, you should see flattened fields such as actor.*, target{}.*, and uuid. &amp;nbsp;To get individual objects in target{}, meanwhile, you should extract target{}, then split multivalues first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| spath path=target{}
| mvexpand target{}
| spath input=target{}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This should give you something like&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;alternateId&lt;/TD&gt;&lt;TD&gt;detailEntry&lt;/TD&gt;&lt;TD&gt;displayName&lt;/TD&gt;&lt;TD&gt;type&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;jane.doe@example.com&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;TD&gt;Doe, Jane&lt;/TD&gt;&lt;TD&gt;User&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;unknown&lt;/TD&gt;&lt;TD&gt;null&lt;/TD&gt;&lt;TD&gt;Good Employees&lt;/TD&gt;&lt;TD&gt;UserGroup&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is an emulation of your illustrated data with that syntax correction. &amp;nbsp;You can play with it and compare with your actual data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval _raw = "{
    \"actor\": {
        \"type\": \"User\",
        \"alternateId\": \"john.smith@example.com\"
    },
    \"target\": [
        {
            \"type\": \"User\",
            \"alternateId\": \"jane.doe@example.com\",
            \"displayName\": \"Doe, Jane\",
            \"detailEntry\": null
        },
        {
            \"type\": \"UserGroup\",
            \"alternateId\": \"unknown\",
            \"displayName\": \"Good Employees\",
            \"detailEntry\": null
        }
    ],
    \"uuid\":\"58dd3885-0c4a-11ee-9843-938af4d00f2c\"
}"
``` data emulation above ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 16:49:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647342#M224053</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-06-16T16:49:40Z</dc:date>
    </item>
    <item>
      <title>Re: Extract multiple JSON fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647349#M224055</link>
      <description>&lt;P&gt;Thank you. Your data is representative of mine. I failed to lint the output after I masked/removed private and irrelevant fields.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 17:44:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647349#M224055</guid>
      <dc:creator>srcno</dc:creator>
      <dc:date>2023-06-16T17:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extract multiple JSON fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647352#M224057</link>
      <description>&lt;P&gt;Thank you. This gave me the output I wanted for most records and was a great starting point for me to clean up - there was no guarantee of the order these options showed up in the array so I am now looking that up with the mvfind.&amp;nbsp;&lt;/P&gt;&lt;P&gt;index=okta eventType="group.user_membership.*"&lt;BR /&gt;| spath actor.alternateId output=Actor&lt;BR /&gt;| spath target{} output=target&lt;BR /&gt;| eval UserPosition = mvfind('target{}.type', "User")&lt;BR /&gt;| eval GroupPosition = mvfind('target{}.type', "UserGroup")&lt;BR /&gt;| eval User=mvindex(target,UserPosition)&lt;BR /&gt;| spath input=User path=alternateId output=User&lt;BR /&gt;| eval Group=mvindex(target,GroupPosition)&lt;BR /&gt;| spath input=Group path=displayName output=Group&lt;BR /&gt;| table Actor Group User&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 18:21:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647352#M224057</guid>
      <dc:creator>srcno</dc:creator>
      <dc:date>2023-06-16T18:21:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extract multiple JSON fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647383#M224063</link>
      <description>&lt;P&gt;You missed mvexpand target. &amp;nbsp;You shouldn't have to use mvfind if you filter by type=User after mvfind. &amp;nbsp;See my answer above.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| mvexpand target{}
| spath input=target{}
| fields - target{}.* target{} _raw
| eval User = if(type == "User", alternateId, null())
| eval Group = if(type == "UserGroup", displayName, null())
| rename actor.alternateId AS Actor
| stats values(User) as User values(Group) as Group by Actor&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 17 Jun 2023 05:48:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Extract-multiple-JSON-fields/m-p/647383#M224063</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-06-17T05:48:22Z</dc:date>
    </item>
  </channel>
</rss>

