<?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 extract a JSON field from another JSON? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698489#M237172</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/269553"&gt;@Codie&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;If your _raw value looks like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "@timestamp": "2024-09-05T10:59:34.826855417+10:00",
  "appName": "TestApp",
  "environment": "UAT",
  "ivUser": "Ashish",
  "level": "INFO",
  "logger": "com.app.login",
  "message": "New user state created - state_id: XXXX-YYYYYY, key_id: twoFactorAuth, key_value: {\"tamSessionIndex\":\"1d1ad722-XXXX-11ef-8a2b-005056b70cf5\",\"devicePrint\":\"DDDDDDDDDDD\",\"createdAt\":\"2099-09-05T00:59:34.734404799Z\",\"updatedAt\":\"2099-09-05T00:59:34.734404799Z\",\"clientSessionId\":\"ppppppppppppp\",\"sessionId\":\"WWWWWWWWW\",\"clientTransactionId\":\"8fd2353d-d609-XXXX-52i6-2e1dc12359m4\",\"transactionId\":\"9285-:f18c10db191:XXXXXXXX_TRX\",\"twoFaResult\":\"CHALLENGE\",\"newDevice\":true,\"newLocation\":false,\"overseas\":true} with TTL: 46825",
  "parentId": "",
  "spanId": "14223cXXXX6d63d5",
  "tamSessionIndex": "1d1ad722-6b22-11ef-8a2b-XXXXXXX",
  "thread": "https-jsse-nio-XXXX-exec-6",
  "traceId": "66d90275ecc565aa61XXXXXXXX02f5815"
}&lt;/LI-CODE&gt;&lt;P&gt;You should have a message field with value:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;New user state created - state_id: XXXX-YYYYYY, key_id: twoFactorAuth, key_value: {"tamSessionIndex":"1d1ad722-XXXX-11ef-8a2b-005056b70cf5","devicePrint":"DDDDDDDDDDD","createdAt":"2099-09-05T00:59:34.734404799Z","updatedAt":"2099-09-05T00:59:34.734404799Z","clientSessionId":"ppppppppppppp","sessionId":"WWWWWWWWW","clientTransactionId":"8fd2353d-d609-XXXX-52i6-2e1dc12359m4","transactionId":"9285-:f18c10db191:XXXXXXXX_TRX","twoFaResult":"CHALLENGE","newDevice":true,"newLocation":false,"overseas":true} with TTL: 46825&lt;/LI-CODE&gt;&lt;P&gt;The key_value data may vary, and you'll need to adjust the regular expression as needed, but as a starting point, you can extract key_value (as message_key_value) and clientTransactionId cleanly in SPL using:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;| rex field=message "key_value: (?&amp;lt;message_key_value&amp;gt;\{.*\}) with TTL:"
| spath input=message_key_value&lt;/LI-CODE&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;| rex field=message "key_value: (?&amp;lt;message_key_value&amp;gt;\{.*\}) with TTL:"
| eval clientTransactionId=json_extract(json(message_key_value), "clientTransactionId")&lt;/LI-CODE&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;| eval clientTransactionId=json_extract(json(replace(message, ".* key_value: (\{.*\}) with TTL: .*", "\\1")), "clientTransactionId")&lt;/LI-CODE&gt;&lt;P&gt;or other variations.&lt;/P&gt;</description>
    <pubDate>Sun, 08 Sep 2024 15:59:31 GMT</pubDate>
    <dc:creator>tscroggins</dc:creator>
    <dc:date>2024-09-08T15:59:31Z</dc:date>
    <item>
      <title>How to extract a JSON field from another JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698476#M237170</link>
      <description>&lt;P&gt;Hi, I would like to extract a field from a JSON logs which is in a prettier format already.&lt;/P&gt;&lt;P&gt;I would like to extract a field named "&lt;SPAN&gt;clientTransactionId&lt;/SPAN&gt;" from below sample data.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A class="" title="" href="https://wbc.splunkcloud.com/en-GB/app/a0089d/search?earliest=1725458400&amp;amp;latest=1725544800&amp;amp;q=search%20(index%3Dprd_applog%20OR%20index%3Dprd_web)%20appid%3A%3Aa0089d%20%0A%20%20%20%20source%3D%22%2Fopt%2Fbtex%2Flogs%2Fprod%2Fbt-identity-management-capability.log%22%20%0A%20%20%20%20%22New%20user%20state%20created%22%20%0A%20%20%20%20%22key_id%3A%20twoFactorAuth%22%20%0A%20%20%20%20clientTransactionId%0A%20%20%20%208fd2353d-508d-4244-82c8-2e1dc12347e0&amp;amp;display.page.search.mode=fast&amp;amp;dispatch.sample_ratio=1&amp;amp;display.page.search.tab=events&amp;amp;display.general.type=events&amp;amp;sid=1725788537.457334_3C288082-06E5-4B51-9010-315EB094C573#" target="_blank" rel="noopener"&gt;[-]&lt;/A&gt;&lt;SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;@timestamp&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;2024-09-05T10:59:34.826855417+10:00&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;appName&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;TestApp&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;environment&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;UAT&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;ivUser&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;Ashish&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;level&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;INFO&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;logger&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;com.app.login&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;message&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;New user state created - state_id: XXXX-YYYYYY, key_id: twoFactorAuth, key_value: {"tamSessionIndex":"1d1ad722-XXXX-11ef-8a2b-005056b70cf5","devicePrint":"DDDDDDDDDDD","createdAt":"2099-09-05T00:59:34.734404799Z","updatedAt":"2099-09-05T00:59:34.734404799Z","clientSessionId":"ppppppppppppp","sessionId":"WWWWWWWWW","&lt;FONT color="#FF0000"&gt;clientTransactionId&lt;/FONT&gt;":"8fd2353d-d609-XXXX-52i6-2e1dc12359m4","transactionId":"9285-:f18c10db191:XXXXXXXX_TRX","twoFaResult":"CHALLENGE","newDevice":true,"newLocation":false,"overseas":true} with TTL: 46825&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;parentId&lt;/SPAN&gt;:&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;spanId&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;14223cXXXX6d63d5&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;tamSessionIndex&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;1d1ad722-6b22-11ef-8a2b-XXXXXXX&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;thread&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;https-jsse-nio-XXXX-exec-6&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;traceId&lt;/SPAN&gt;:&amp;nbsp;&lt;SPAN class=""&gt;66d90275ecc565aa61XXXXXXXX02f5815&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2024 10:01:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698476#M237170</guid>
      <dc:creator>Codie</dc:creator>
      <dc:date>2024-09-08T10:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a JSON field from another JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698489#M237172</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/269553"&gt;@Codie&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;If your _raw value looks like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
  "@timestamp": "2024-09-05T10:59:34.826855417+10:00",
  "appName": "TestApp",
  "environment": "UAT",
  "ivUser": "Ashish",
  "level": "INFO",
  "logger": "com.app.login",
  "message": "New user state created - state_id: XXXX-YYYYYY, key_id: twoFactorAuth, key_value: {\"tamSessionIndex\":\"1d1ad722-XXXX-11ef-8a2b-005056b70cf5\",\"devicePrint\":\"DDDDDDDDDDD\",\"createdAt\":\"2099-09-05T00:59:34.734404799Z\",\"updatedAt\":\"2099-09-05T00:59:34.734404799Z\",\"clientSessionId\":\"ppppppppppppp\",\"sessionId\":\"WWWWWWWWW\",\"clientTransactionId\":\"8fd2353d-d609-XXXX-52i6-2e1dc12359m4\",\"transactionId\":\"9285-:f18c10db191:XXXXXXXX_TRX\",\"twoFaResult\":\"CHALLENGE\",\"newDevice\":true,\"newLocation\":false,\"overseas\":true} with TTL: 46825",
  "parentId": "",
  "spanId": "14223cXXXX6d63d5",
  "tamSessionIndex": "1d1ad722-6b22-11ef-8a2b-XXXXXXX",
  "thread": "https-jsse-nio-XXXX-exec-6",
  "traceId": "66d90275ecc565aa61XXXXXXXX02f5815"
}&lt;/LI-CODE&gt;&lt;P&gt;You should have a message field with value:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;New user state created - state_id: XXXX-YYYYYY, key_id: twoFactorAuth, key_value: {"tamSessionIndex":"1d1ad722-XXXX-11ef-8a2b-005056b70cf5","devicePrint":"DDDDDDDDDDD","createdAt":"2099-09-05T00:59:34.734404799Z","updatedAt":"2099-09-05T00:59:34.734404799Z","clientSessionId":"ppppppppppppp","sessionId":"WWWWWWWWW","clientTransactionId":"8fd2353d-d609-XXXX-52i6-2e1dc12359m4","transactionId":"9285-:f18c10db191:XXXXXXXX_TRX","twoFaResult":"CHALLENGE","newDevice":true,"newLocation":false,"overseas":true} with TTL: 46825&lt;/LI-CODE&gt;&lt;P&gt;The key_value data may vary, and you'll need to adjust the regular expression as needed, but as a starting point, you can extract key_value (as message_key_value) and clientTransactionId cleanly in SPL using:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;| rex field=message "key_value: (?&amp;lt;message_key_value&amp;gt;\{.*\}) with TTL:"
| spath input=message_key_value&lt;/LI-CODE&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;| rex field=message "key_value: (?&amp;lt;message_key_value&amp;gt;\{.*\}) with TTL:"
| eval clientTransactionId=json_extract(json(message_key_value), "clientTransactionId")&lt;/LI-CODE&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;| eval clientTransactionId=json_extract(json(replace(message, ".* key_value: (\{.*\}) with TTL: .*", "\\1")), "clientTransactionId")&lt;/LI-CODE&gt;&lt;P&gt;or other variations.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2024 15:59:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698489#M237172</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2024-09-08T15:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a JSON field from another JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698493#M237173</link>
      <description>&lt;P&gt;First and foremost - this is not a json within a json. This is a json object embedded within something that resembles json&amp;nbsp; but is syntactically incorrect. I suspect you're getting that data with some filebeat, logstash or similar tool. I'd try to fix the format to be a proper well-formed json. Then it "just works".&lt;/P&gt;&lt;P&gt;EDIT: Ok, that's what you get when you're not posting raw data, but rather the preformatted output from webui. Still the key_value part should be a proper object containing key-value pairs, not an embedded string. That makes no sense. Fix your data.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2024 17:54:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698493#M237173</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-09-08T17:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a JSON field from another JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698496#M237174</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Still the key_value part should be a proper object containing key-value pairs, not an embedded string. That makes no sense. Fix your data.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This is incredibly common and in most cases, outside the control of the destination. In the Logstash/Elasticsearch world, I'd parse the message field with a grok filter/processor followed by a json filter/processor to parse key_value into a JSON object. ("Elastic" translates to "overhead," but it's really just a trade-off relative to how Lucene works.) In the Splunk world, I'd leave it as is and use search-time field extractions, field aliases, etc. and accelerated data models.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Sep 2024 18:09:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698496#M237174</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2024-09-08T18:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a JSON field from another JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698498#M237175</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/49493"&gt;@tscroggins&lt;/a&gt;&amp;nbsp;Perfect. Worked smoothly.&lt;BR /&gt;&lt;BR /&gt;I took a long way as follows:&lt;BR /&gt;| spath&lt;BR /&gt;| rename message as _raw&lt;BR /&gt;| extract&lt;BR /&gt;| rex "\"sessionId\"\:\"(?&amp;lt;SessionID&amp;gt;.*?)\"\,\"clientTransactionId\"\:\"(?&amp;lt;ClientTransactionId&amp;gt;.*?)\"\,\"transactionId\""&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 00:06:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698498#M237175</guid>
      <dc:creator>Codie</dc:creator>
      <dc:date>2024-09-09T00:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract a JSON field from another JSON?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698535#M237191</link>
      <description>&lt;P&gt;I know. You are receiving what they send you. But you can often just talk with the sending party &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Anyway, since it looks like there is something ELK-like in the middle, it could be worthwhile to check the ingestion process architecture - why are there middle men? Are we ingesting into multiple desitnations from single source? Maybe we could drop the extra stuff and not only lower our license consumption but also make our data compatible with existing TAs?&lt;/P&gt;&lt;P&gt;So the short-time soluion is of course to extract the string from one field of the json and run spath on it (there is no way I know of to do it automatically unless you want to get messy with regexes on this - another reason for getting your data tidy). But long-term solution IMO is to get the data right.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Sep 2024 09:16:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-a-JSON-field-from-another-JSON/m-p/698535#M237191</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-09-09T09:16:20Z</dc:date>
    </item>
  </channel>
</rss>

