<?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 Iterating thru json array in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Iterating-thru-json-array/m-p/578322#M47372</link>
    <description>&lt;P&gt;Hi sorry if this has been asked before, spent lot of time researching but can't find quite the answer.&lt;/P&gt;&lt;P&gt;I have this json logged below, I want to do analysis on the order lines, so need a search to return two lines from my json example.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Order Reference&lt;/TD&gt;&lt;TD&gt;Description&lt;/TD&gt;&lt;TD&gt;Value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XXX&lt;/TD&gt;&lt;TD&gt;PAUL&lt;/TD&gt;&lt;TD&gt;35,700&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XXX&lt;/TD&gt;&lt;TD&gt;IS GREAT&lt;/TD&gt;&lt;TD&gt;42,000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I've tried a million things, can't get it to work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Paul (who isn't actually that great!)&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;THE JSON&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;&amp;nbsp; "orderReference": "xxx",&lt;BR /&gt;&amp;nbsp; "orderLine": [&lt;BR /&gt;&amp;nbsp; {&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"orderLineUserItemDescription": "PAUL",&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"orderLineUnitPrice": "35700.0",&lt;BR /&gt;&amp;nbsp; &amp;nbsp;},&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;{&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"orderLineUserItemDescription": "IS GREAT",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"orderLineUnitPrice": "42000.0",&lt;BR /&gt;&amp;nbsp; &amp;nbsp;} ]&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Tue, 14 Dec 2021 14:00:50 GMT</pubDate>
    <dc:creator>eckythump</dc:creator>
    <dc:date>2021-12-14T14:00:50Z</dc:date>
    <item>
      <title>Iterating thru json array</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Iterating-thru-json-array/m-p/578322#M47372</link>
      <description>&lt;P&gt;Hi sorry if this has been asked before, spent lot of time researching but can't find quite the answer.&lt;/P&gt;&lt;P&gt;I have this json logged below, I want to do analysis on the order lines, so need a search to return two lines from my json example.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Order Reference&lt;/TD&gt;&lt;TD&gt;Description&lt;/TD&gt;&lt;TD&gt;Value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XXX&lt;/TD&gt;&lt;TD&gt;PAUL&lt;/TD&gt;&lt;TD&gt;35,700&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;XXX&lt;/TD&gt;&lt;TD&gt;IS GREAT&lt;/TD&gt;&lt;TD&gt;42,000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I've tried a million things, can't get it to work &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Paul (who isn't actually that great!)&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;THE JSON&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;&amp;nbsp; "orderReference": "xxx",&lt;BR /&gt;&amp;nbsp; "orderLine": [&lt;BR /&gt;&amp;nbsp; {&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"orderLineUserItemDescription": "PAUL",&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"orderLineUnitPrice": "35700.0",&lt;BR /&gt;&amp;nbsp; &amp;nbsp;},&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;{&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"orderLineUserItemDescription": "IS GREAT",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;"orderLineUnitPrice": "42000.0",&lt;BR /&gt;&amp;nbsp; &amp;nbsp;} ]&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 14:00:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Iterating-thru-json-array/m-p/578322#M47372</guid>
      <dc:creator>eckythump</dc:creator>
      <dc:date>2021-12-14T14:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating thru json array</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Iterating-thru-json-array/m-p/578324#M47373</link>
      <description>&lt;P&gt;One doesn't iterate through the array.&amp;nbsp; The array is treated as a single entity so we have to split it into separate events.&amp;nbsp; Something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults | eval _raw="{
  \"orderReference\": \"xxx\",
  \"orderLine\": [
  { 
     \"orderLineUserItemDescription\": \"PAUL\",  
     \"orderLineUnitPrice\": \"35700.0\"
   }, 
   { 
     \"orderLineUserItemDescription\": \"IS GREAT\",
     \"orderLineUnitPrice\": \"42000.0\"
   }
   ]
}" | spath
```Everything above just sets up test data```
```Rename the fields for convenience```
| rename orderLine{}.orderLineUserItemDescription as Description, orderLine{}.orderLineUnitPrice as Value
```Match up Description and Value pairs```
| eval DV=mvzip(Description,Value, ";")
```Split the Description/Value pairs into separate events```
| mvexpand DV
```Break the Description/Value pairs apart```
| eval DV=split(DV,";")
| eval Description = mvindex(DV,0), Value=mvindex(DV, 1)
```Display the results```
| table orderReference Description Value&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 14 Dec 2021 14:06:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Iterating-thru-json-array/m-p/578324#M47373</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-12-14T14:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating thru json array</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Iterating-thru-json-array/m-p/578335#M47374</link>
      <description>&lt;P&gt;Alternatively:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults | eval _raw="{
  \"orderReference\": \"xxx\",
  \"orderLine\": [
  { 
     \"orderLineUserItemDescription\": \"PAUL\",  
     \"orderLineUnitPrice\": \"35700.0\"
   }, 
   { 
     \"orderLineUserItemDescription\": \"IS GREAT\",
     \"orderLineUnitPrice\": \"42000.0\"
   }
   ]
}" 


| spath orderLine{} output=orderLine
| mvexpand orderLine
| spath input=orderLine
| spath orderReference
| rename orderReference as "Order Reference", orderLineUnitPrice as Value, orderLineUserItemDescription as Description
| table "Order Reference" Description Value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 14:59:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Iterating-thru-json-array/m-p/578335#M47374</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-12-14T14:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating thru json array</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Iterating-thru-json-array/m-p/578367#M47376</link>
      <description>&lt;P&gt;You&amp;nbsp; are a genius!&amp;nbsp; Thank you so much for answering so quickly, works amazingly and learned a lot in this post.&lt;/P&gt;&lt;P&gt;Drinks on me if you ever pass thru Atlanta!&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;</description>
      <pubDate>Tue, 14 Dec 2021 18:28:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Iterating-thru-json-array/m-p/578367#M47376</guid>
      <dc:creator>eckythump</dc:creator>
      <dc:date>2021-12-14T18:28:44Z</dc:date>
    </item>
  </channel>
</rss>

