Troubles with a Chrome Extension for JSON

I'm currently working on a project to develop a Google Chrome extension and I've encountered an obstacle. I'm experimenting with JSON data (with the intention of integrating it with an API in the future). I have a sample JSON file, successfully loaded it into my code, and stored the parsed JSON as a variable. However, I'm unsure how to access specific values within the objects.

var xhr = new XMLHttpRequest();
var resp;
xhr.open("GET", "eg.json", true);
xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
    resp = JSON.parse(xhr.responseText);
  }
}
xhr.send();

After executing the send request, the object resp takes on the appearance shown here.

As someone who is relatively new to JavaScript, I'm struggling to figure out how to retrieve the createdDate value as a String variable. Any assistance would be greatly appreciated!

Thank you

Answer №1

To access the information, you can utilize either the dot or bracket notation in JavaScript, depending on the scenario. It is recommended to use bracket notation for dynamic properties. An example based on the provided image is as follows:

var registrationDate = resp.WhoisRecord.audit.registrationDate;

It is important to note that this code should be called within the specific if statement where resp is defined. The data will only be populated inside that callback function during the xhr.onreadystatechange assignment. Attempting to use it outside of this context may result in it not being ready when executed.

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

Is it possible to run my JavaScript script immediately following the execution of npm run build?

Hey everyone! I am trying to run my JavaScript file right after receiving the successful message from npm run build. Currently, I am working on a Vue.js codebase. Is there a way for me to log and create a file in my code repository containing the 'run ...

Turning a group of objects into a JSON format

In my current setup, I have a RESTful web service utilizing Spring, Hibernate, c3p0, and Sybase, all running on Tomcat. This service functions as a search engine, returning a collection of objects based on specific search criteria. These objects have a com ...

I am unable to make changes to the datatable located in another form

I'm experiencing difficulty updating the datatable in a separate form. javax.servlet.ServletException: Cannot locate component with identifier "searchForm:dataTableId" referenced from "criteriaForm:j_idt13". javax.faces.webapp.FacesServlet.servic ...

Tips for eliminating the left and bottom border in a React chart using Chart.js 2

Is there a way to eliminate the left and bottom borders as shown in the image? ...

Having trouble with Socket.io and its io.emit() method refusing to work? If communication from server to client isn't going smoothly, you may need a solution for sending data from the server to

My latest project is a document converter program that utilizes LibreOffice to convert documents to PDF format. Here's my server running on localhost:3000 import express from "express"; import bodyParser from "body-parser"; import ...

What is the recommended lifecycle hook in Vue.js2 to execute a function when the page is loaded?

I have a dynamic table that can be filled with various numbers of rows, and I want to add an overlay before the data is loaded using my applyOverlay() function. Below is the structure of my HTML: <table id="table" class="datatable" s ...

Exploring the depths of nested JSON structures with ReactJS

I'm facing an issue while trying to access the nested data from my JSON. The error message that keeps popping up is "Cannot read property 'map' of undefined". I've searched for solutions and watched tutorials, but the problem persists. ...

Learn how to subscribe to Azure Event Grid using Angular without the need for a backend service layer

I am currently working on an Angular project and I am looking to set up Azure Event Grid subscription directly from the client-side without the need for a backend service. After exploring different options, I have not yet found a straightforward solution. ...

Switch up the CSS file based on the URL route

My project consists of the following files: App.vue, changcolor.vue, config.json, main.js, index.html, xyz.css, abc.css. I need a solution where based on the URL, the appropriate CSS file is applied. For instance, if the URL is "xyz.local.com" then xyz.cs ...

Describe a Typescript Interface Value as a collection of strings or any input provided as an argument

Uncertain if the question title is accurate - currently developing react components within a library that has specific predefined values for certain properties. However, additional values may need to be added on a per usage basis. So far, this setup is fun ...

Controller unable to retrieve Ajax data

I am facing an issue with my code where the search model data is coming up as nulls, while the pageNumber is being received properly in its controller counterpart. I'm not sure where I might have made a mistake. $("#NextResult").click(function () { ...

Establishing the initial value for an input file form

Similar Question: Dynamically set value of a file input I'm currently working with an HTML form that includes a file input field, and I'm attempting to set the initial value for the file path in the form. I've tried changing the "value" ...

The AJAX success callback function failed to execute in cases where the dataType was set to JSONP during Cross domain Access

type = 'math'; var ajurl = "sample.com&callback=myhandler"; var datas = "cateid=" + cateid + "&type=" + type + "&pno=" + pno + "&whos=" + whos; $.ajax({ type: "GET", url: ajurl, data: datas, contentType: "application/json; ...

unable to utilize the library three.js

I stumbled upon an interesting animation on Codepen that uses blocks to reconstruct a map image. The necessary JavaScript files are three.min.js and TweenMax.min.js. I copied the links from Codepen and pasted them into my HTML using <script src="">&l ...

Transferring a variable value between functions using autocomplete and AJAX communication

I am facing difficulties with implementing autocomplete jQuery along with AJAX call. The issue arises when a user enters text in the input field, triggering an AJAX POST request to the controller which retrieves values from the database and sends them back ...

Add a singular item to a JSON file without modifying the entire contents

I'm currently developing a process that utilizes JSON.NET to incorporate a new horse object into a database of horses formatted in JSON. One approach involves deserializing the entire file into a list of horses, adding the new horse, and then serializ ...

What is the process for logging out when a different user signs in using Firebase authentication in a React Native application?

I am new to React Native and facing challenges with managing authentication state in my application. Currently, I am using Redux but have not yet implemented persistence for user login. I have incorporated Firebase authentication. Essentially, I would li ...

Overriding the w-4xl with sm:text-2xl in Tailwind CSS

Struggling to achieve responsive design on my Pages, especially with changing text size when the screen is small. I've been following all the correct steps and maintaining the right order. However, whenever I set 'sm', it seems to override a ...

What is the best way to eliminate an item from an array in JavaScript or AngularJS?

I'm attempting to eliminate objects from an array and retrieve the resulting array. I've been using a remove function, but it's not functioning as expected. Here is the input I'm working with: The goal is to remove all values in the ar ...

Exploring the functionality of dynamic component imports in jest testing

Under a specific condition, I dynamically imported a component and stored it in an object property. Then, I displayed it in the template using vue <component :is="">. Everything is functioning correctly at the component level. However, I am ...