<?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 Trouble parsing JSON coming via REST in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Trouble-parsing-JSON-coming-via-REST/m-p/318448#M59505</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;

&lt;P&gt;I have a JSON that looks like this (the repeting elements have been removed):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  {  
       "data":{  
          "viewer":{  
             "homes":[  
                {  
                   "currentSubscription":{  
                      "status":"running",
                      "priceInfo":{  
                         "range":{  
                            "nodes":[  
                               {  
                                  "total":0.5375,
                                  "energy":0.43,
                                  "tax":0.1075,
                                  "startsAt":"2018-02-28T09:00:00+01:00",
                                  "currency":"NOK"
                               },
                               {  
                                  "total":0.5371,
                                  "energy":0.4297,
                                  "tax":0.1074,
                                  "startsAt":"2018-02-28T10:00:00+01:00",
                                  "currency":"NOK"
                               },
                               {  
                                  "total":0.526,
                                  "energy":0.4208,
                                  "tax":0.1052,
                                  "startsAt":"2018-02-28T11:00:00+01:00",
                                  "currency":"NOK"
                               }
                            ]
                         }
                      }
                   }
                }
             ]
          }
       }
    }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm really having problems getting this JSON parsed when the data comes into SPLUNK via REST.&lt;/P&gt;

&lt;P&gt;I'm pulling the data once every day, so I want the "startsAt" to be the time for which I want to be the _time field. I want to have this done as a sourcetype.&lt;/P&gt;

&lt;P&gt;In general, the data I want out of this JSON is like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;            _time                   total   energy  tax currency
event   2018-02-28T09:00:00+01:00   0.5375  0.43    0.1075  NOK
event   2018-02-28T10:00:00+01:00   0.5371  0.4297  0.1074  NOK
event   2018-02-28T11:00:00+01:00   0.526   0.4208  0.1052  NOK
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 04 Mar 2018 15:48:58 GMT</pubDate>
    <dc:creator>chrzz</dc:creator>
    <dc:date>2018-03-04T15:48:58Z</dc:date>
    <item>
      <title>Trouble parsing JSON coming via REST</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Trouble-parsing-JSON-coming-via-REST/m-p/318448#M59505</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;

&lt;P&gt;I have a JSON that looks like this (the repeting elements have been removed):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  {  
       "data":{  
          "viewer":{  
             "homes":[  
                {  
                   "currentSubscription":{  
                      "status":"running",
                      "priceInfo":{  
                         "range":{  
                            "nodes":[  
                               {  
                                  "total":0.5375,
                                  "energy":0.43,
                                  "tax":0.1075,
                                  "startsAt":"2018-02-28T09:00:00+01:00",
                                  "currency":"NOK"
                               },
                               {  
                                  "total":0.5371,
                                  "energy":0.4297,
                                  "tax":0.1074,
                                  "startsAt":"2018-02-28T10:00:00+01:00",
                                  "currency":"NOK"
                               },
                               {  
                                  "total":0.526,
                                  "energy":0.4208,
                                  "tax":0.1052,
                                  "startsAt":"2018-02-28T11:00:00+01:00",
                                  "currency":"NOK"
                               }
                            ]
                         }
                      }
                   }
                }
             ]
          }
       }
    }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm really having problems getting this JSON parsed when the data comes into SPLUNK via REST.&lt;/P&gt;

&lt;P&gt;I'm pulling the data once every day, so I want the "startsAt" to be the time for which I want to be the _time field. I want to have this done as a sourcetype.&lt;/P&gt;

&lt;P&gt;In general, the data I want out of this JSON is like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;            _time                   total   energy  tax currency
event   2018-02-28T09:00:00+01:00   0.5375  0.43    0.1075  NOK
event   2018-02-28T10:00:00+01:00   0.5371  0.4297  0.1074  NOK
event   2018-02-28T11:00:00+01:00   0.526   0.4208  0.1052  NOK
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Mar 2018 15:48:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Trouble-parsing-JSON-coming-via-REST/m-p/318448#M59505</guid>
      <dc:creator>chrzz</dc:creator>
      <dc:date>2018-03-04T15:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble parsing JSON coming via REST</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Trouble-parsing-JSON-coming-via-REST/m-p/318449#M59506</link>
      <description>&lt;P&gt;@chrzz, following is a run anywhere search based on the sample data provided:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{  
    \"data\":{  
       \"viewer\":{  
          \"homes\":[  
             {  
                \"currentSubscription\":{  
                   \"status\":\"running\",
                   \"priceInfo\":{  
                      \"range\":{  
                         \"nodes\":[  
                            {  
                               \"total\":0.5375,
                               \"energy\":0.43,
                               \"tax\":0.1075,
                               \"startsAt\":\"2018-02-28T09:00:00+01:00\",
                               \"currency\":\"NOK\"
                            },
                            {  
                               \"total\":0.5371,
                               \"energy\":0.4297,
                               \"tax\":0.1074,
                               \"startsAt\":\"2018-02-28T10:00:00+01:00\",
                               \"currency\":\"NOK\"
                            },
                            {  
                               \"total\":0.526,
                               \"energy\":0.4208,
                               \"tax\":0.1052,
                               \"startsAt\":\"2018-02-28T11:00:00+01:00\",
                               \"currency\":\"NOK\"
                            }
                         ]
                      }
                   }
                }
             }
          ]
       }
    }
 }"
 | spath
 | rename data.viewer.homes{}.currentSubscription.priceInfo.range.nodes{}.* as *
 | eval data=mvzip(startsAt,mvzip(energy,mvzip(tax,mvzip(total,currency))))
 | fields - _*
 | fields data
 | mvexpand data
 | makemv data delim=","
 | eval _time=strptime(mvindex(data,0),"%Y-%m-%dT%H:%M:%S"), energy=mvindex(data,1), tax=mvindex(data,2), total=mvindex(data,3), currency=mvindex(data,4)
 | fields - data
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 04 Mar 2018 19:31:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Trouble-parsing-JSON-coming-via-REST/m-p/318449#M59506</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-03-04T19:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble parsing JSON coming via REST</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Trouble-parsing-JSON-coming-via-REST/m-p/318450#M59507</link>
      <description>&lt;P&gt;Thanks! But, this is only after the data have been indexed. I want this to be done at index-time in a sourcetype. How can I write the correct way to get the data into splunk the correct way?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 08:19:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Trouble-parsing-JSON-coming-via-REST/m-p/318450#M59507</guid>
      <dc:creator>chrzz</dc:creator>
      <dc:date>2018-03-05T08:19:32Z</dc:date>
    </item>
  </channel>
</rss>

