The JSON reviver function is still not returning anything even when explicitly using the return

function _quotedText(data, config) {
    var pathKeys=config.customKey;  
    console.log(pathKeys);         //prints os_platform
    var inAuth_data=(JSON.parse(JSON.parse(JSON.parse(data["event.fields.custom_fields.inauth_device_data"])), (key, value) => {
        if (key == pathKeys)
        {
            console.log(value);     //prints Android
            return value;           //returns undefined
        }
    }));

    console.log(inAuth_data);       //prints undefined
    return inAuth_data;             //returns undefined
}

I have encountered a similar issue before and attempted various solutions suggested by others but I am still facing the problem. Why does the function return 'undefined'?

The JSON data causing the trouble is as follows:

"\"{\\\"deviceInfo\\\":{\\\"permanentId\\\":\\\"23434433-3333-4444-9581-f9cb641d28f5\\\",\\\"publicSigningKey\\\":\\\"MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAzMRW6jXVgqX0QV0EA9h2XnnPvntER5yqPKvD+yLKtxXzBCYMzygEM1nlwBRZhVpNJFvzZ2X+oTLGasdbasjhddasdu0PAWIc1AqKMt6rDEJv4a8bgqqAnXXnvR/QjwtsIq3T59LqivcoB2IPGq7Mof7yRJXKtrEOK2a1b8ixWJ5MBZ06drONhMkzeDTKjenMSM0Hf3BFTlXKCF...

Answer №1

After spending some time struggling with it, I finally managed to figure out the solution. It turned out that the function was called for each object in the JSON. And after

if (key == pathKeys)

was verified, the value was printed and returned. However, there were additional objects in the JSON string following the matched key, which resulted in them being replaced on the variable inAuth_data.

Therefore, I simply had to create another variable outside the reviver function and set its value when the condition was met.

function _quotedText(data, config) {
var pathKeys=config.customKey;  
console.log(pathKeys);         //displays os_platform
var data = undefined;
var inAuth_data =(JSON.parse(JSON.parse(JSON.parse(data["event.fields.custom_fields.inauth_device_data"])), (key, value) => {
    if (key == pathKeys)
    {
        console.log(value);     //displays Android
        data = value;           //Assigning value of value to data
    }
  }));

console.log(inAuth_data);       //displays Android
return inAuth_data;             //returns Android

}

A big thank you to @evolutionxbox for collaborating with me on this issue.

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

Trouble with Background Image Display in Internet Explorer 8

I have been attempting to set a background image for the . element, but it is not displaying correctly. The image shows up in Firefox and Chrome, but not in Internet Explorer. I have included a link to my website and relevant CSS code below. Can anyone pro ...

Using Jquery to swap out div elements and reinitialize code after selecting a menu <a href>link<</a>

I have a jQuery script that swaps out a div when a href="#1" is clicked. The same link, a href="#1", is then replaced by a href="#2" and vice versa. Here is the jQuery code: $('.child2, a[href="#1"]').hide() $('#replacepagelinks a').c ...

Receiving JSON data in TypeScript and displaying it in a structured table format

I am just starting to learn TypeScript, I need to be able to handle JSON data of varying sizes... Once I receive the data, I want to display it in a table format... The structure of my JSON data will resemble this: [{"regionID":1 "regionname":"Can"}, ...

Using jQuery and Laravel framework to handle a POST request

Could someone assist me with troubleshooting a jQuery post request issue? I suspect there may be an error with the routes or controller. Here is my JavaScript code for the post request: $.post('http://localhost:8000/ajax', { ...

How to incorporate a delay in ng-repeat using AngularJS

Currently, I am facing an issue with my ng-repeat block. In this block, I am generating elements based on data received from an ajax request, which sometimes causes a delay due to latency. Within the same block, I have implemented a filter to remove unwant ...

Creating a resilient node websocket client with enhanced security (overcoming the challenge of verifying the initial certificate)

What's Working? I successfully created a node server using WebSocket technology. I used the library WebSocket-Node and added key/cert to my HTTPS/secure websocket server as shown below: import WebSockerServer from "websocket"; import fs fro ...

Looking for assistance with parsing a JSON string within a SQL stored procedure and extracting the values of its attributes

Is there a more efficient way to parse JSON strings in a SQL stored procedure and update corresponding fields of tables based on the attributes? For example, I want to extract specific information from a JSON string that looks like this: {"category1":{"f ...

Using MediaQuery from react-responsive to selectively hide individual JSX attributes

I have a button element that includes both the Profile Picture and the Info, which consists of the first name and last name. My goal is to hide only the profile picture (profileImageProps={profileImageAndBasicInfoProps.profileImageProps}) when the screen ...

Submit button in React form not activating the onSubmit method

Having an issue with a login form code where the submit handler is not being triggered when pressing the Submit button. Any idea what could be causing this? The loginHandler function does not seem to trigger, but the handleInputChange function works fine. ...

recording the results of a Node.js program in PHP using exec

I'm attempting to retrieve the output from my node.js script using PHP exec wrapped within an ajax call. I am able to make the call and receive some feedback, but I can't seem to capture the console.log output in the variable. This is how I exec ...

Basic parallax application, failing to achieve the desired impact

My goal is to create a scrolling effect where the header text moves down slightly, adding some margin on top to keep it in view. I found the perfect example of what I want to achieve with the header text at this website: After spending hours working on i ...

Utilizing AJAX to send RSS feeds to a Django view

I'm fairly new to using ajax. Here's the scenario I'm dealing with: I'm working on a side project that involves displaying news and scores for various sports. To achieve this, I'm utilizing rss feeds from different sources. In my D ...

What are some methods for transferring the state variable's value from one component to another in React?

I have the following scenario in my code: there is a Form.js component that interacts with an API, stores the response in the walletAssets state variable, and now I want to create a separate Display.js component to present this data. How can I pass the v ...

Ways to extract a single digit from the total sum of a date in the format of 15-06-2015

Is there a way to extract a single digit from the sum of a number in date format, such as 15-06-2015? My goal is to convert the date format 15-06-2015 into a single-digit value by adding up the numbers. For instance: In the case of 15-05-2015, the output ...

Can you guide me on implementing an onclick event using HTML, CSS, and JavaScript?

I am looking for a way to change the CSS codes of the blog1popup class when the image is clicked. I already know how to do this using hover, but I need help making it happen on click instead. The element I want to use as the button; <div class=&quo ...

"In JavaScript, the use of double quotes within a string is

What is the best way to include double quotes in a JavaScript string for display on a webpage? I'm currently tackling my JavaScript assignment and need to insert double quotes within a list, like the example below: if (i == 0) { error += "<l ...

Is it possible to trigger a Bootstrap 5.2 Popover within an "if" statement?

As part of my input validation process, I am utilizing popovers. However, I am struggling with the syntax to make it work as intended. https://jsbin.com/sufitelodo/1/edit?html,js,output The JSBin provided serves as the foundation for this issue. I am un ...

Unable to alter the vertex color in three.js PointCloud

I'm currently facing an issue with changing the color of a vertex on a mouse click using three.js and Angular. After doing some research, I believe that setting up vertex colors is the way to go. My approach involves setting up vertex colors and then ...

What is the best way to implement client side validation for a related input field using JavaScript in a Rails application?

Struggling to find a solution for adding a validation check for a dropdown list that is dependent on another input selection in a different form. It seems like database validation may be necessary, but I'm unsure of the best approach. Any suggestions ...

Is it necessary for me to use a .jsx extension when saving my React component files?

After working with React for a few months, I recently noticed that some of my files have the .js extension while others have the .jsx extension. Surprisingly, when I write JSX code in the .js files, everything still functions correctly. Is there any signif ...