<?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 Json and extract all fields in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-Json-and-extract-all-fields/m-p/488362#M83579</link>
    <description>&lt;P&gt;You can use this command on the datajson field you extracted to grab all fields: &lt;CODE&gt;| spath input=datajson&lt;/CODE&gt;&lt;BR /&gt;
Here's a run anywhere example using your data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval data=" 20191119:132817.646  64281752e393 [EJB default - 7] WARN  com.company.MyClass - My Textwarning  –  ID 1,111,111,111 ID2 12313. DataJson: {  \"antragKopf\": \"kopfdata\",  \"gesperrt\": false,  \"roid\": \"12321\",  \"rolle\": \"TEST\",  \"sprache\": \"de\",  \"letzterVersuch\": \"2019-11-19 13:28:02.876\",  \"anzahlVersuche\": 12,  \"aktStatus\": \"MY_STATUS\",  \"fehlerInfo\": \"myerror\",  \"erstelltAm\": \"2019-11-18 16:18:35.244\",  \"policennummer\": 123,  \"version\": 12,  \"systemmeldung\": null,  \"isNotwendig\": true,  \"voData\": null,  \"abbruchGrund\": \"NPNE\",  \"id\": 11111}"
| rex field=data "DataJson: (?&amp;lt;datajson&amp;gt;.*)"
| spath input=datajson
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Be careful with this though as this can use a ton of memory and disk on a search if you have a large amount of data.  It's better to identify what fields you need from the  json and do either rex or eval spath the fields out like you have been, but if that is not working for you the above method will accomplish what you are asking for.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Nov 2019 15:22:38 GMT</pubDate>
    <dc:creator>dmarling</dc:creator>
    <dc:date>2019-11-21T15:22:38Z</dc:date>
    <item>
      <title>How to parse Json and extract all fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-Json-and-extract-all-fields/m-p/488361#M83578</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
I have a logstatement that contains a json. &lt;BR /&gt;
I am able to parse the json as field. I am also able to parse each field of the json. But only each field by hand.&lt;BR /&gt;
Is there anyway of like parsing all 1st level fields by hand?&lt;/P&gt;

&lt;P&gt;My result is this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;20191119:132817.646  64281752e393 [EJB default - 7] WARN  com.company.MyClass - My Textwarning  –  ID 1,111,111,111 ID2 12313. DataJson: {  "antragKopf": "kopfdata",  "gesperrt": false,  "roid": "12321",  "rolle": "TEST",  "sprache": "de",  "letzterVersuch": "2019-11-19 13:28:02.876",  "anzahlVersuche": 12,  "aktStatus": "MY_STATUS",  "fehlerInfo": "myerror",  "erstelltAm": "2019-11-18 16:18:35.244",  "policennummer": 123,  "version": 12,  "systemmeldung": null,  "isNotwendig": true,  "voData": null,  "abbruchGrund": "NPNE",  "id": 11111}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can get the JSON data with this query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;app=opc javaclass="com.company.MyClass" "My Textwarning" | rex "DataJson: (?&amp;lt;datajson&amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I want to extract all first level json attributes as fields (I want to use the fields in an email later)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;app=opc javaclass="com.company.MyClass" "My Textwarning" | rex "DataJson: (?&amp;lt;datajson&amp;gt;.*)"  | eval json-antragKopf = spath(datajson, "antragKopf") | eval json-gesperrt = spath(datajson, "gesperrt") | eval json-gesperrt = spath(datajson, "gesperrt") | 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there any simple way of extracting all attributes without specifying each one by hand?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 11:59:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-Json-and-extract-all-fields/m-p/488361#M83578</guid>
      <dc:creator>philschneiderax</dc:creator>
      <dc:date>2019-11-21T11:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to parse Json and extract all fields</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-Json-and-extract-all-fields/m-p/488362#M83579</link>
      <description>&lt;P&gt;You can use this command on the datajson field you extracted to grab all fields: &lt;CODE&gt;| spath input=datajson&lt;/CODE&gt;&lt;BR /&gt;
Here's a run anywhere example using your data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval data=" 20191119:132817.646  64281752e393 [EJB default - 7] WARN  com.company.MyClass - My Textwarning  –  ID 1,111,111,111 ID2 12313. DataJson: {  \"antragKopf\": \"kopfdata\",  \"gesperrt\": false,  \"roid\": \"12321\",  \"rolle\": \"TEST\",  \"sprache\": \"de\",  \"letzterVersuch\": \"2019-11-19 13:28:02.876\",  \"anzahlVersuche\": 12,  \"aktStatus\": \"MY_STATUS\",  \"fehlerInfo\": \"myerror\",  \"erstelltAm\": \"2019-11-18 16:18:35.244\",  \"policennummer\": 123,  \"version\": 12,  \"systemmeldung\": null,  \"isNotwendig\": true,  \"voData\": null,  \"abbruchGrund\": \"NPNE\",  \"id\": 11111}"
| rex field=data "DataJson: (?&amp;lt;datajson&amp;gt;.*)"
| spath input=datajson
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Be careful with this though as this can use a ton of memory and disk on a search if you have a large amount of data.  It's better to identify what fields you need from the  json and do either rex or eval spath the fields out like you have been, but if that is not working for you the above method will accomplish what you are asking for.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2019 15:22:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-parse-Json-and-extract-all-fields/m-p/488362#M83579</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2019-11-21T15:22:38Z</dc:date>
    </item>
  </channel>
</rss>

