<?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 JSON nested field extraction in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/JSON-nested-field-extraction/m-p/582309#M202827</link>
    <description>&lt;P&gt;I have the following JSON:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "kind": "report",
    "id": {
        "time": "2021-12-24T15:45:01.331Z",
    },
    "events": [
        {
            "parameters": [
                {
                    "name": "field1",
                    "boolValue": true
                },
                {
                    "name": "field2",
                    "boolValue": true
                },
                {
                    "name": "field3",
                    "value": "value3"
                },
                {
                    "name": "field4",
                    "value": "value4"
                },
                {
                    "name": "field5",
                    "boolValue": false
                },
                {
                    "name": "field6",
                    "value": "value6"
                },
                {
                    "name": "field7",
                    "value": "value7"
                },
                {
                    "name": "field8",
                    "boolValue": false
                },
                {
                    "name": "field9",
                    "value": "value9"
                },
                {
                    "name": "field10",
                    "boolValue": false
                },
                {
                    "name": "field11",
                    "boolValue": false
                }
            ]
        }
    ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to marry the key/value pairing of name/value and name/boolValue with their corresponding values i.e.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;field1: true&lt;BR /&gt;field4: value4&lt;BR /&gt;&lt;BR /&gt;I've attempted to use spath to extract values, but keep coming up short.&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jan 2022 19:43:34 GMT</pubDate>
    <dc:creator>wilcomply13</dc:creator>
    <dc:date>2022-01-24T19:43:34Z</dc:date>
    <item>
      <title>JSON nested field extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/JSON-nested-field-extraction/m-p/582309#M202827</link>
      <description>&lt;P&gt;I have the following JSON:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "kind": "report",
    "id": {
        "time": "2021-12-24T15:45:01.331Z",
    },
    "events": [
        {
            "parameters": [
                {
                    "name": "field1",
                    "boolValue": true
                },
                {
                    "name": "field2",
                    "boolValue": true
                },
                {
                    "name": "field3",
                    "value": "value3"
                },
                {
                    "name": "field4",
                    "value": "value4"
                },
                {
                    "name": "field5",
                    "boolValue": false
                },
                {
                    "name": "field6",
                    "value": "value6"
                },
                {
                    "name": "field7",
                    "value": "value7"
                },
                {
                    "name": "field8",
                    "boolValue": false
                },
                {
                    "name": "field9",
                    "value": "value9"
                },
                {
                    "name": "field10",
                    "boolValue": false
                },
                {
                    "name": "field11",
                    "boolValue": false
                }
            ]
        }
    ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to marry the key/value pairing of name/value and name/boolValue with their corresponding values i.e.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;field1: true&lt;BR /&gt;field4: value4&lt;BR /&gt;&lt;BR /&gt;I've attempted to use spath to extract values, but keep coming up short.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 19:43:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/JSON-nested-field-extraction/m-p/582309#M202827</guid>
      <dc:creator>wilcomply13</dc:creator>
      <dc:date>2022-01-24T19:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: JSON nested field extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/JSON-nested-field-extraction/m-p/582486#M202878</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=_raw max_match=0 "\"name\"\:\s?\"?(?&amp;lt;field_name&amp;gt;[^\"^,]*)\"?\,\s+\"\w+\"\:\s?\"?(?&amp;lt;field_value&amp;gt;[^\"^\n]*)"
| eval fields_list=mvzip(field_name, field_value, ":")
| eval _raw=mvjoin(mvzip(field_name, field_value, ":"),"|")
| extract pairdelim="=|",kvdelim=":"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 07:55:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/JSON-nested-field-extraction/m-p/582486#M202878</guid>
      <dc:creator>johnhuang</dc:creator>
      <dc:date>2022-01-26T07:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: JSON nested field extraction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/JSON-nested-field-extraction/m-p/582716#M202944</link>
      <description>&lt;P&gt;For structured data like JSON, I still prefer buildin SPL commands to custom regex so even badly formatted, but syntactically correct inputs do not ruin extraction. &amp;nbsp;The same idea can be implemented with&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/8.2.0/SearchReference/Spath" target="_blank"&gt;spath&lt;/A&gt;, for example:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex mode=sed "s/boolValue/value/g" ``` treat boolValue just like string value ```
| rex mode=sed "s/\"\"/\"()\"/g" ``` compensate for spath's lack of zero-length standin ```
| spath
| rename events{}.parameters{}.* as field_*
``` johnhua's original code below ```
| eval _raw=mvjoin(mvzip(field_name, field_value, ":"),"|")
| extract pairdelim="=|",kvdelim=":"&lt;/LI-CODE&gt;&lt;P&gt;A caveat with spath is that it doesn't have an option to provide a standin for zero-length string values, so I have to force a non-zero standin.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jan 2022 10:26:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/JSON-nested-field-extraction/m-p/582716#M202944</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2022-01-27T10:26:04Z</dc:date>
    </item>
  </channel>
</rss>

