<?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 JSON parsing: fieldsAdd or in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/JSON-parsing-fieldsAdd-or/m-p/244159#M838</link>
    <description>&lt;P&gt;I have a DQL which filters down to one of two possible JSONs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;content = {"code":"an_error_code","error":{"code":"an_error_code","message":"An error message appears here..."}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;content = {"level":"error","message":"Some error here..."}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I want is: timestamp + error code (or empty string) + error message. So far, I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch logs
| filter k8s.namespace.name == "default"
| filter contains(content, "error")
| parse content, "JSON:parsedJSON"
| fieldsAdd error_code = parsedJSON[error][code], error_message = (parsedJSON[message] or parsedJSON[error][message])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 29 Apr 2024 05:28:21 GMT</pubDate>
    <dc:creator>ghfsa</dc:creator>
    <dc:date>2024-04-29T05:28:21Z</dc:date>
    <item>
      <title>JSON parsing: fieldsAdd or</title>
      <link>https://community.dynatrace.com/t5/DQL/JSON-parsing-fieldsAdd-or/m-p/244159#M838</link>
      <description>&lt;P&gt;I have a DQL which filters down to one of two possible JSONs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;content = {"code":"an_error_code","error":{"code":"an_error_code","message":"An error message appears here..."}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;content = {"level":"error","message":"Some error here..."}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output I want is: timestamp + error code (or empty string) + error message. So far, I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch logs
| filter k8s.namespace.name == "default"
| filter contains(content, "error")
| parse content, "JSON:parsedJSON"
| fieldsAdd error_code = parsedJSON[error][code], error_message = (parsedJSON[message] or parsedJSON[error][message])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Apr 2024 05:28:21 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/JSON-parsing-fieldsAdd-or/m-p/244159#M838</guid>
      <dc:creator>ghfsa</dc:creator>
      <dc:date>2024-04-29T05:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: JSON parsing: fieldsAdd or</title>
      <link>https://community.dynatrace.com/t5/DQL/JSON-parsing-fieldsAdd-or/m-p/245286#M872</link>
      <description>&lt;P&gt;This should do it&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data record(timestamp=now(), content = """{"code":"an_error_code","error":{"code":"an_error_code","message":"An error message appears here..."}}"""),
     record(timestamp=now(), content = """{"level":"error","message":"Some error here..."}""")

| parse content, "JSON:parsedJSON"
| fieldsAdd error_code = parsedJSON[error][code], error_message = if (isNull(parsedJSON[message]), parsedJSON[error][message], else:parsedJSON[message])
| fieldsAdd output=concat(toString(timestamp),"--- ",error_code, " ",error_message )
| fields output&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 08:58:33 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/JSON-parsing-fieldsAdd-or/m-p/245286#M872</guid>
      <dc:creator>FranciscoGarcia</dc:creator>
      <dc:date>2024-05-10T08:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: JSON parsing: fieldsAdd or</title>
      <link>https://community.dynatrace.com/t5/DQL/JSON-parsing-fieldsAdd-or/m-p/245288#M873</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="FranciscoGarcia_0-1715331108149.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/19752i1F1D3795017D5EE2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="FranciscoGarcia_0-1715331108149.png" alt="FranciscoGarcia_0-1715331108149.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 08:52:22 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/JSON-parsing-fieldsAdd-or/m-p/245288#M873</guid>
      <dc:creator>FranciscoGarcia</dc:creator>
      <dc:date>2024-05-10T08:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: JSON parsing: fieldsAdd or</title>
      <link>https://community.dynatrace.com/t5/DQL/JSON-parsing-fieldsAdd-or/m-p/245307#M875</link>
      <description>&lt;P&gt;Simpler way to express:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;error_message = if (isNull(parsedJSON[message]), parsedJSON[error][message], else:parsedJSON[message])&lt;/LI-CODE&gt;&lt;P&gt;is using &lt;EM&gt;&lt;STRONG&gt;coalesce&lt;/STRONG&gt;&lt;/EM&gt; function&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;error_message =coalesce(parsedJSON[message], parsedJSON[error][message])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kris&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 12:06:00 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/JSON-parsing-fieldsAdd-or/m-p/245307#M875</guid>
      <dc:creator>krzysztof_hoja</dc:creator>
      <dc:date>2024-05-10T12:06:00Z</dc:date>
    </item>
  </channel>
</rss>

