<?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: Json Parsing. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Json-Parsing/m-p/674727#M230965</link>
    <description>&lt;P&gt;Thanks you very much , your solution worked perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jan 2024 18:59:36 GMT</pubDate>
    <dc:creator>onthakur</dc:creator>
    <dc:date>2024-01-18T18:59:36Z</dc:date>
    <item>
      <title>Json Parsing.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Json-Parsing/m-p/674709#M230958</link>
      <description>&lt;P&gt;I have below json and I want table of url and corresponding duration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;"details": {&lt;BR /&gt;"sub-trans": [&lt;BR /&gt;{&lt;BR /&gt;"app-trans-id": "123",&lt;BR /&gt;"sub-trans-id": "234",&lt;BR /&gt;"startTime": "2024-01-18T12:37:12.482Z",&lt;BR /&gt;"endTime": "2024-01-18T12:37:12.502Z",&lt;BR /&gt;"duration": 20,&lt;/P&gt;&lt;P&gt;"req": {&lt;BR /&gt;"url": "&lt;A href="http://abc123" target="_blank" rel="noopener"&gt;http://abc123&lt;/A&gt;",&lt;BR /&gt;&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"app-trans-id": "123",&lt;BR /&gt;"sub-trans-id": "567",&lt;BR /&gt;"startTime": "2024-01-18T12:37:12.506Z",&lt;BR /&gt;"endTime": "2024-01-18T12:37:12.550Z",&lt;BR /&gt;"duration": 44,&lt;BR /&gt;&lt;BR /&gt;"req": {&lt;BR /&gt;"url": "&lt;A href="https://xyz567" target="_blank" rel="noopener"&gt;https://xyz567&lt;/A&gt;",&lt;BR /&gt;&lt;BR /&gt;},&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using below splunk query but duration field is not populating in table.&lt;/P&gt;&lt;P&gt;Kindly help&lt;/P&gt;&lt;P&gt;index=hello&lt;BR /&gt;|spath output=url details.sub-trans{}.req.url| mvexpand url&lt;BR /&gt;|spath output=duration details.sub-trans{}.duration |mvexpand duration&lt;BR /&gt;|table url,duration&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 17:18:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Json-Parsing/m-p/674709#M230958</guid>
      <dc:creator>onthakur</dc:creator>
      <dc:date>2024-01-18T17:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Json Parsing.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Json-Parsing/m-p/674722#M230962</link>
      <description>&lt;P&gt;The duration field populates in my sandbox, but values are duplicated.&amp;nbsp; That's likely because the two &lt;FONT face="courier new,courier"&gt;mvexpand&lt;/FONT&gt; calls break the association between url and duration.&amp;nbsp; Try this query, instead:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=hello
| spath output=url details.sub-trans{}.req.url
| spath output=duration details.sub-trans{}.duration
``` Combine url and duration ```
| eval pairs=mvzip(url,duration)
``` Put each pair into a separate event ```
| mvexpand pairs
``` Extract the url and duration fields ```
| eval pairs=split(pairs,","), url=mvindex(pairs,0), duration=mvindex(pairs,1)
| table url,duration&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 18:19:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Json-Parsing/m-p/674722#M230962</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2024-01-18T18:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Json Parsing.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Json-Parsing/m-p/674725#M230963</link>
      <description>&lt;P&gt;By going off what you pasted it is coming back as an invalid JSON, I would check that first.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_1-1705601292399.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28999i0B73283ED3C598D7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_1-1705601292399.png" alt="dtburrows3_1-1705601292399.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But assuming that it is just a copy/paste error and you do have a valid json object as _raw then I would probably do an spath like this to retain associations between url and durations.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=hello
    | spath input=_raw path=details.sub-trans{} output=sub_trans
    | fields - _raw
    | table sub_trans
    | mvexpand sub_trans
    | spath input=sub_trans
    | fields - sub_trans&lt;/LI-CODE&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="dtburrows3_0-1705601059634.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28998i2CD3A9AF87C6CC39/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_0-1705601059634.png" alt="dtburrows3_0-1705601059634.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;You can see here all the field are extracted and they maintained their relationships to their individual url/duration according to the structure of detail.sub-trans{} array. Does require an mvexpand though, just keep an eye out for memory limits.&lt;BR /&gt;&lt;BR /&gt;To retain specific associations of the url to its respective duration by extracting both as individual multivalued fields &lt;STRONG&gt;is possible&lt;/STRONG&gt; &lt;EM&gt;but can be problematic&lt;/EM&gt;. If any of them have a null entry for whatever reason then all associations are thrown off from that point on. Thats why in these sort of situations I would much rather extract the entire nested json object out of the array, mvexpand that, then spath that internal json.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Also want to note that doing a mvexpand against two multivalue fields like in your original search will completely loose all association between which url should have which duration. you will actually end up with N^2 results when by the structure of the json I believe there should only be N results.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 18:54:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Json-Parsing/m-p/674725#M230963</guid>
      <dc:creator>dtburrows3</dc:creator>
      <dc:date>2024-01-18T18:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Json Parsing.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Json-Parsing/m-p/674727#M230965</link>
      <description>&lt;P&gt;Thanks you very much , your solution worked perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 18:59:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Json-Parsing/m-p/674727#M230965</guid>
      <dc:creator>onthakur</dc:creator>
      <dc:date>2024-01-18T18:59:36Z</dc:date>
    </item>
  </channel>
</rss>

