Unable to find JSON data using the Javascript Kafka Magic Tool, as no results are being

In JSON format, I have a message that contains various details. My goal is to utilize Javascript search functionality to identify if the EmailAddress matches the specific value I am looking for within hundreds of similar messages:

 "Message": {
          "Event": {
            "Type": "INFO",
            "IsSuccessful": true,
            "Details": {
              "Value": "{\"EmailAddress\":\"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bfcbdacccbffcbdacccb91dcd0d2">[email protected]</a>\",\"SystemId\":\"5\"}"
            }

This is the code snippet I have been using:

function findItem(items) {
    
    if (!items) return console.log('failed');
    for (i=0; i < items.length; i++) {
        if (items[i].Event.Details.Value.EmailAddress === "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c78697f784c78697f78226f6361">[email protected]</a>\") return console.log('found');
    } 
    return console.log('fail 2');
}

return findItem(Context.Message);

I seem to be encountering an issue as my search function is not triggering the console.log('found')

UPDATE* I would like to mention that this scenario involves the use of Kafka Magic Tool - https://www.kafkamagic.com/usage/development/#:~:text=validating%20a%20producer.-,Use%20JavaScript%20queries%20to%20search%20for%20a%20message,fields%2C%20headers%2C%20and%20metadata.

Answer №1

items[i].Event.Details.Value contains JSON data that needs to be decoded using JSON.parse() before you can access the .EmailAddress property.

You can use a function like the one below for this purpose:

function findItem(items) {
    if (!items) return false;
    for (i=0; i < items.length; i++) {
        let parsedDetails = JSON.parse(items[i].Event.Details.Value);
        if (parsedDetails.EmailAddress === "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="99edfceaedd9edfceaedb7faf6f4">[email protected]</a>") {
            console.log('found', items[i]);
            return true;
        }
    }
    return false;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I'm confused about what I did wrong with Node.js. The server.js is up and running, but I'm unable to view the

I have made some progress so far and I am currently running this code on Putty. var http = require('http'); var fs = require('fs'); const PORT = 8080; http.createServer(function(request, response) { var url = request.url; switc ...

JavaScript code to make titles slide in as the user scrolls

Looking for a better way to make all titles slide in upon scrolling instead of coding individually? Consider using a forEach loop! Here's how you can modify the code below: function slideInLeft() { document.querySelectorAll('.subtitle-left ...

What could be the reason behind the malfunctioning of $.getjson?

I've been facing issues trying to access remote json data. Initially, I resorted to using as a temporary fix but it's no longer serving the purpose for me. As of now, I am back at square one trying to resolve why I am unable to retrieve the remo ...

Combining Mouseover and Click Events in Vue JS

Having four pictures, I want to display a specific component when hovering over them. However, I also need to bind the click event so that clicking on the picture will reveal the component. The challenge is that I am unable to simultaneously bind two event ...

Integrating chat functionality with a structured data format

Considering creating a collaborative communication platform, I am contemplating whether to develop a comprehensive application in JavaScript with MVC architecture or utilize it solely for managing message delivery using Node.js and socketIO. Would it be m ...

Should the page.js in a Next.js App router be a server component?

Is it standard practice in Next.js 13 and above (App router) for the page.js of all routes/folders to be a server component? I know that it can be a client component with use client, but is this advisable or are there potential issues during the build proc ...

Is there a way to prevent advertisements from appearing in npm?

As I execute various npm commands, my console gets bombarded with ads promoting different projects and individuals. While I enjoy contributing to open source projects, I believe the console output of a tool should not be used for advertising. Thank you fo ...

Looking to maintain the value of a toggle button in a specific state depending on certain condition checks

I have a situation where I need to keep a toggle button set to "off" if my collection object is empty. Previously, I was using v-model to update the value of the toggle button. However, now I am attempting to use :value and input events, but I am strugglin ...

Implementing the IF statement in jQuery

I've been trying to implement an overflow check when hovering over a div. The issue arises because I'm using jQuery for the hover function and then simple JavaScript for the overflow check in the next step. It seems that directly using an if-then ...

MongoDB excluding initial element

When working with MongoDB in Java, I am encountering a scenario where I need to insert documents (Persons) into a collection. The JSON example that I receive looks like this: {"Person": { "Name": "", "Firstname": "" }} My question is, when inserting ...

Creating dynamic HTML elements for each section using JavaScript

Is there a way to dynamically add a task (input + label) for each specific section/div when entering the name and pressing the "Add" button? I attempted to create an event for each button to add a task for the corresponding div of that particular section, ...

Stop the HTML5 video playback within a slider (flickity)

As I add slides to a slider using flickity, I am encountering an issue where the first video pauses when there is a slide change event. However, if I play the video on the next slide and then move back or forward, the video does not pause. This is my curr ...

Uncover the hidden message in a string encoded for JavaScript

This encoded HTML code is intended for use in a JavaScript function <div class=\"ProductDetail\"><div style=\"width:780px\">\r\n\t<div class=\"baslik\" style=\"margin: 0px; padding: 5px 10px ...

Ways to trigger a JavaScript function upon submission of my form

I have created a code snippet to validate and submit a contact form: formValidation: function() { if ( this.formData.name && this.formData.company && this.formData.email && this.formData.industry && this.formData.phone && this.fo ...

There is a gap found in the span element in Angular, but this gap is not seen in

Comparing two component templates, one in AngularJS and the other in modern Angular: <span ng-repeat="status in statusInformation.statusList | filter : whereFilter" class="show-on-hover"> <span class="app-icon ap ...

What is the process for incorporating a new URL into the routes.js file of a preexisting Node.js project that was developed with locomotive?

module.exports = function routes() { this.root('pages#main'); this.match('/status', 'pages#status'); this.resources('paper'); this.resources('tempform'); this.match('/paper/domain', 'pages#n ...

Custom transaction settings for Mongoose

When conducting transactions, we often have the ability to customize certain options. For example, we can specify transaction options like the ones shown below: const transactionOptions = { readPreference: 'primary', readConcern: { level: &ap ...

I am interested in running JavaScript code on a page that has been loaded through AJAX

I am struggling to execute the Javascript loaded within an ajax page. Here is the link to my loaded ajax page: https://jsfiddle.net/4dsbry7j/ JS : var xmlhttp = new XMLHttpRequest(); var url = "http://localhost/ajax/find2.php"; xmlhttp.onreadystatechang ...

Creating an empty array of objects in Vue 3 requires using the Vue 3 syntax

In my project using Vue3 with Nuxt, I encountered an issue. My goal is to initialize an empty array of objects and then populate it. let results = ref([]); results.value = [ { "name": input.value, } ...

Maximizing Efficiency of Vendor Bundle in Angular 2 with Webpack

My MEAN application's client side is built in Angular2 with Webpack, but I'm facing slow loading times due to a large vendor modules JS file. Is there a way to optimize this situation? I want to separate the vendor's JS file. Below is my we ...