<?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: How do you unpivot my JSON data? in Deployment Architecture</title>
    <link>https://community.splunk.com/t5/Deployment-Architecture/How-do-you-unpivot-my-JSON-data/m-p/380953#M21189</link>
    <description>&lt;P&gt;Hi @mrogers_t,&lt;/P&gt;

&lt;P&gt;I would suggest you to fix extra double quotes (like &lt;CODE&gt;"&lt;/CODE&gt; after &lt;CODE&gt;"message":&lt;/CODE&gt;) on source instead of splunk to make perfect JSON event. Until you will fix that you can use REGEX with SED to remove that &lt;CODE&gt;"&lt;/CODE&gt; at search time.&lt;/P&gt;

&lt;P&gt;Please try below query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
| rex field=_raw mode=sed  "s/(?s)(?:(\"message\"\:\s)\"(\{.*\})\"(\,.*\})\")/\1\2\3/"
| spath
| rename message.timers.* AS *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Below is run anywhere search based on sample data which is generating fields like &lt;CODE&gt;createAllTags.end&lt;/CODE&gt;, &lt;CODE&gt;createAllTags.start&lt;/CODE&gt; etc.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{
     \"time\": \"2018-12-26 14:48:25.554\",
     \"log_level\": \"INFO\",
     \"logger_name\": \"testLogger\",
     \"message\": \"{
         \"timers\": {
             \"total\": {
                 \"start\": 1545835678315,
                 \"end\": 1545835705554
             },
             \"readUDTParentTypes\": {
                 \"start\": 1545835698394,
                 \"end\": 1545835698571
             },
             \"createAllTags\": {
                 \"start\": 1545835705500,
                 \"end\": 1545835705546
             },
             \"createDS\": {
                 \"start\": 1545835705546,
                 \"end\": 1545835705554
             },
             \"identifyUniqueUDTs\": {
                 \"start\": 1545835698571,
                 \"end\": 1545835705500
             }
         }\",
         \"totalTime\": 27.239,
     }\"
 }"
| rex field=_raw mode=sed  "s/(?s)(?:(\"message\"\:\s)\"(\{.*\})\"(\,.*\})\")/\1\2\3/"
| spath
| rename message.timers.* AS *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 27 Dec 2018 10:17:17 GMT</pubDate>
    <dc:creator>harsmarvania57</dc:creator>
    <dc:date>2018-12-27T10:17:17Z</dc:date>
    <item>
      <title>How do you unpivot my JSON data?</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/How-do-you-unpivot-my-JSON-data/m-p/380952#M21188</link>
      <description>&lt;P&gt;I'm not sure if 'unpivot' is the right term, but I'm not sure what the term would be. I'm having trouble searching for help for this problem.&lt;/P&gt;

&lt;P&gt;I have this JSON (note the quotes around the brackets for the 'message' value. This is output returned by Ignition SCADA and thats just how it comes. I know use spath on it and that sorts it out.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{
    "time": "2018-12-26 14:48:25.554",
    "log_level": "INFO",
    "logger_name": "testLogger",
    "message": "{
        "timers": {
            "total": {
                "start": 1545835678315,
                "end": 1545835705554
            },
            "readUDTParentTypes": {
                "start": 1545835698394,
                "end": 1545835698571
            },
            "createAllTags": {
                "start": 1545835705500,
                "end": 1545835705546
            },
            "createDS": {
                "start": 1545835705546,
                "end": 1545835705554
            },
            "identifyUniqueUDTs": {
                "start": 1545835698571,
                "end": 1545835705500
            }
        }",
        "totalTime": 27.239,
    }"
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I'd like to do for each of these events is to create multiple rows, one for each entry in timers, like a field for the timer name, a field for start, and a field for stop. I'm pretty sure this is going to be some mvzip/mvexpand magic, but I haven't worked with that enough to see how it fits together.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Dec 2018 17:32:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/How-do-you-unpivot-my-JSON-data/m-p/380952#M21188</guid>
      <dc:creator>mrogers_t</dc:creator>
      <dc:date>2018-12-26T17:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do you unpivot my JSON data?</title>
      <link>https://community.splunk.com/t5/Deployment-Architecture/How-do-you-unpivot-my-JSON-data/m-p/380953#M21189</link>
      <description>&lt;P&gt;Hi @mrogers_t,&lt;/P&gt;

&lt;P&gt;I would suggest you to fix extra double quotes (like &lt;CODE&gt;"&lt;/CODE&gt; after &lt;CODE&gt;"message":&lt;/CODE&gt;) on source instead of splunk to make perfect JSON event. Until you will fix that you can use REGEX with SED to remove that &lt;CODE&gt;"&lt;/CODE&gt; at search time.&lt;/P&gt;

&lt;P&gt;Please try below query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseSearch&amp;gt;
| rex field=_raw mode=sed  "s/(?s)(?:(\"message\"\:\s)\"(\{.*\})\"(\,.*\})\")/\1\2\3/"
| spath
| rename message.timers.* AS *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Below is run anywhere search based on sample data which is generating fields like &lt;CODE&gt;createAllTags.end&lt;/CODE&gt;, &lt;CODE&gt;createAllTags.start&lt;/CODE&gt; etc.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="{
     \"time\": \"2018-12-26 14:48:25.554\",
     \"log_level\": \"INFO\",
     \"logger_name\": \"testLogger\",
     \"message\": \"{
         \"timers\": {
             \"total\": {
                 \"start\": 1545835678315,
                 \"end\": 1545835705554
             },
             \"readUDTParentTypes\": {
                 \"start\": 1545835698394,
                 \"end\": 1545835698571
             },
             \"createAllTags\": {
                 \"start\": 1545835705500,
                 \"end\": 1545835705546
             },
             \"createDS\": {
                 \"start\": 1545835705546,
                 \"end\": 1545835705554
             },
             \"identifyUniqueUDTs\": {
                 \"start\": 1545835698571,
                 \"end\": 1545835705500
             }
         }\",
         \"totalTime\": 27.239,
     }\"
 }"
| rex field=_raw mode=sed  "s/(?s)(?:(\"message\"\:\s)\"(\{.*\})\"(\,.*\})\")/\1\2\3/"
| spath
| rename message.timers.* AS *
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Dec 2018 10:17:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Deployment-Architecture/How-do-you-unpivot-my-JSON-data/m-p/380953#M21189</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-12-27T10:17:17Z</dc:date>
    </item>
  </channel>
</rss>

