<?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 to parse a json tree into a table? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112431#M29538</link>
    <description>&lt;P&gt;I don't know the BEST solution for this kind of problem, but one approach is to attack it in two passes.&lt;/P&gt;

&lt;P&gt;In pass one, you extract each segment as a blob of json in a field.  You then have a multivalue field of segments, and can use mvexpand to get two results, one with each segment.&lt;/P&gt;

&lt;P&gt;At this point you can use spath again to pull out the list of expressions as multivalue fields, process them as neededed and mvexpand again to get a full table.&lt;/P&gt;

&lt;P&gt;Note that mvexpand is written such that it will duplicate all the information in all the fields, so if for example your original item has hundreds of kilobytes of json you might want to trim the original event with |fields to toss away _raw before performing your |mvexpand action.&lt;/P&gt;</description>
    <pubDate>Fri, 14 Nov 2014 16:09:27 GMT</pubDate>
    <dc:creator>jrodman</dc:creator>
    <dc:date>2014-11-14T16:09:27Z</dc:date>
    <item>
      <title>How to parse a json tree into a table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112429#M29536</link>
      <description>&lt;P&gt;the following seach string basically pulls out the JSON puts it in a variable called data and then runs it through spath.  I then output two elements from the json.  What I get is a couple of multivalue fields but the second table shows what I want.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=fulfillment com.x.y.u.i.segment.SegmentJoinDataWorkflow category | rex ".*SegmentJoinDataWorkflow: (?.*)" | spath input=data | rename segments{}.customSegmentName AS customSegmentName, segments{}.expression{}.$and{}.$and{}.$or{}.category as category | table _time,customSegmentName,category


2014-11-13 14:42:56     Test117182801LVRPublSD2Adv                     5256
                        Test117182802LVRPublSD2Adv                     5257
                                                                       5987
                                                                       5000
                                                                       5256
                                                                       5257
                                                                       5987
                                                                       5000 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;2nd table Basically taking the json tree structure and flatten it out into multiple events&lt;/STRONG&gt;&lt;BR /&gt;
Any help on how to do this would be appreciated.  I have tried a number of things with the mv[commands] mvexpand,mvzip, mvappend, makemv etc..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;2014-11-13 14:42:56    Test117182801LVRPublSD2Adv                    5256
2014-11-13 14:42:56    Test117182801LVRPublSD2Adv                    5257
2014-11-13 14:42:56    Test117182801LVRPublSD2Adv                    5987
2014-11-13 14:42:56    Test117182801LVRPublSD2Adv                    5000
**2014-11-13 14:42:56  Test117182802LVRPublSD2Adv                    5256
2014-11-13 14:42:56    Test117182802LVRPublSD2Adv                    5257
2014-11-13 14:42:56    Test117182802LVRPublSD2Adv                    5987
2014-11-13 14:42:56    Test117182802LVRPublSD2Adv                    5000** 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My JSON:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{ "accountInfo" : { "policyType" : "basic",
      "shareAccountId" : "1063216919"
    },
  "adId" : "40283453",
  "isRequired" : "true",
  "manualApproval" : [ "no" ],
  "notification" : { "DATALOADER" : { "failureUrl" : "http://batch/status/",
          "successUrl" : "http://status/"
        },
      "EMAIL" : { "email" : [ "" ] }
    },
  "notifyUser" : [ "onAll" ],
  "packageId" : "1171824434543",
  "packageName" : "Test11718244DataApp",
  "PartnerId" : "5034534",
  "segments" : [ { "id_count" : 112,
        "controlPercent" : 20,
        "count" : "123",
        "customSegmentId" : "1171824401",
        "customSegmentName" : "Test1171824401Dataloader",
        "expression" : [ { "$and" : [ { "$and" : [ { "$or" : [ { "category" : "5256" },
                              { "category" : "5257" }
                            ] } ] },
                  { "$and" : [ { "$or" : [ { "category" : "5987" },
                              { "category" : "5000" }
                            ] } ] }
                ] } ],
        "locations" : [ "" ],
        "total_ashid_count" : 100
      },
      { "id_count" : 112,
        "controlPercent" : 20,
        "count" : "123",
        "customSegmentId" : "1171824402",
        "customSegmentName" : "Test1171824402Dataloader",
        "expression" : [ { "$and" : [ { "$and" : [ { "$or" : [ { "category" : "5256" },
                              { "category" : "5257" }
                            ] } ] },
                  { "$and" : [ { "$or" : [ { "category" : "5987" },
                              { "category" : "5000" }
                            ] } ] }
                ] } ],
        "locations" : [ "" ],
        "total_id_count" : 100
      }
    ],
  "username" : "",
}
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Nov 2014 22:25:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112429#M29536</guid>
      <dc:creator>bradyguy</dc:creator>
      <dc:date>2014-11-13T22:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a json tree into a table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112430#M29537</link>
      <description>&lt;P&gt;I tried to put the tables back together, and quoted the JSON while at it.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Nov 2014 16:03:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112430#M29537</guid>
      <dc:creator>jrodman</dc:creator>
      <dc:date>2014-11-14T16:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a json tree into a table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112431#M29538</link>
      <description>&lt;P&gt;I don't know the BEST solution for this kind of problem, but one approach is to attack it in two passes.&lt;/P&gt;

&lt;P&gt;In pass one, you extract each segment as a blob of json in a field.  You then have a multivalue field of segments, and can use mvexpand to get two results, one with each segment.&lt;/P&gt;

&lt;P&gt;At this point you can use spath again to pull out the list of expressions as multivalue fields, process them as neededed and mvexpand again to get a full table.&lt;/P&gt;

&lt;P&gt;Note that mvexpand is written such that it will duplicate all the information in all the fields, so if for example your original item has hundreds of kilobytes of json you might want to trim the original event with |fields to toss away _raw before performing your |mvexpand action.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Nov 2014 16:09:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112431#M29538</guid>
      <dc:creator>jrodman</dc:creator>
      <dc:date>2014-11-14T16:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a json tree into a table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112432#M29539</link>
      <description>&lt;P&gt;Um, i have a simpler json that looks like this:&lt;/P&gt;

&lt;P&gt;{&lt;BR /&gt;
  "qos-definition": [&lt;BR /&gt;
    {&lt;BR /&gt;
      "bool": "false",&lt;BR /&gt;
      "description": "Active Directory Connect Response",&lt;BR /&gt;
      "hasMax": "false",&lt;BR /&gt;
      "name": "QOS_AD_CONNECT_RESPONSE",&lt;BR /&gt;
      "qosDefId": "28",&lt;BR /&gt;
      "qosGroup": "QOS_APPLICATION",&lt;BR /&gt;
      "type": "0",&lt;BR /&gt;
      "unit": "ms",&lt;BR /&gt;
      "unitShort": "ms"&lt;BR /&gt;
    },&lt;BR /&gt;
    {&lt;BR /&gt;
      "bool": "false",&lt;BR /&gt;
      "description": "Active Directory Replication Age",&lt;BR /&gt;
      "hasMax": "false",&lt;BR /&gt;
      "name": "QOS_AD_REPLICATION_AGE",&lt;BR /&gt;
      "qosDefId": "29",&lt;BR /&gt;
      "qosGroup": "QOS_APPLICATION",&lt;BR /&gt;
      "type": "0",&lt;BR /&gt;
      "unit": "s",&lt;BR /&gt;
      "unitShort": "s"&lt;BR /&gt;
    },&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;I have in a field "result" (which i get from a custom commando that just gets it from a RESTful Webservice) and then i split it and use extract. Maybe this helps a little: &lt;/P&gt;

&lt;P&gt;| eval results=split(results,"{") | mvexpand results| rename results AS _raw| eval _raw = substr(_raw, 1, len(_raw)-2) | extract pairdelim=",", kvdelim=":" | fields - _raw&lt;/P&gt;

&lt;P&gt;extract seems to work on _raw but split and mvexpand don't seem to like _raw. The substr() is to get rid of trailing "}," but that is more of a nice coincidence with the json in my case.&lt;/P&gt;

&lt;P&gt;Hope this helps a little?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:50:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112432#M29539</guid>
      <dc:creator>dominiquevocat</dc:creator>
      <dc:date>2020-09-28T19:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse a json tree into a table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112433#M29540</link>
      <description>&lt;P&gt;Can you edit props.conf to process json files? &lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/Admin/Propsconf?utm_source=answers&amp;amp;utm_medium=in-answer&amp;amp;utm_term=props.conf&amp;amp;utm_campaign=refdoc"&gt;http://docs.splunk.com/Documentation/Splunk/latest/Admin/Propsconf?utm_source=answers&amp;amp;utm_medium=in-answer&amp;amp;utm_term=props.conf&amp;amp;utm_campaign=refdoc&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;and then something like:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE&gt;search | rex "(?\{.*\})" |  spath input=json_input  |table fields
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 04 Dec 2015 23:11:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-parse-a-json-tree-into-a-table/m-p/112433#M29540</guid>
      <dc:creator>sk8asd123</dc:creator>
      <dc:date>2015-12-04T23:11:51Z</dc:date>
    </item>
  </channel>
</rss>

