Steps for extracting the value of a new Date object passed in a JSON format

After retrieving data from a REST service, I encountered the following JSON structure:

{  
    "data":{  
       "virt":false,
       "someValue":"0.0",
       "dateFrom":new Date(1519772400000),
       "anotherValue":""
   }
}

I am unsure how to properly handle fields containing the new Date(1519772400000) object during parsing. Neither JSON.parse() nor response.json() seem to be effective for this task. My ultimate goal is to create an object based on the received JSON data.

If anyone has suggestions for a straightforward method of parsing this information without resorting to creating a specialized parser or resorting to regular expressions, your input would be greatly appreciated.

Thank you.

Answer №1

The recommended approach is to store and retrieve a JSON structure similar to the following example:

{  
    "information":{  
        "activeStatus":true,
        "numericValue":"2.0",
        "startDate": 1520127600000,
        "additionalProperty":"sample"
    }
}

The JSON snippet provided in your inquiry does not adhere to the correct syntax.

Answer №2

Everything is functioning as expected, there are no issues with the REST output.

[UPDATE] It might have been more preferable if the output was in Unixtimestamp or a similar format.[/UPDATE]

Here is how you can interpret it:

let jsonData = {  
    "data":{  
       "virt":false,
       "someValue":"0.0",
       "dateFrom":new Date(1519772400000),
       "anotherValue":""
   }
}

let dateValue = jsonData.data.dateFrom

console.log(dateValue)
console.log(Date.parse(dateValue))

Check out this JSFiddle demo

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

How can Vue.js use the v-if directive for events?

Is it possible to react to an event within a vue template? For example, if a child component dispatches an event like $dispatch('userAdded'), can I display a message in the parent component based on that? <div class="alert alert-info" v-if="u ...

How can I add text to a textbox within a duplicated div using Javascript or Jquery?

I'm looking to add text to a cloned div's text box using jQuery. I have a div with a button and text box, and by cloning it, I want to dynamically insert text into the new div. $(document).ready(function () { $("#click").click(function () { ...

Creating Dynamic Forms in React with Typescript: A Step-by-Step Guide to Adding Form Elements with an onClick Event Handler

I am looking to create a dynamic generation of TextFields and then store their values in an array within the state. Here are my imports: import TextField from '@material-ui/core/TextField'; import Button from '@material-ui/core/Button&apos ...

When attempting to make an .ajax call within the select_node.jstree event for nodes that are not leaf nodes, the call is unsuccessful

When I make an AJAX call using $.ajax, everything works perfectly fine when the select_node.jstree event is triggered, except for non-leaf nodes. In this scenario, although the server receives the Ajax request and sends back the data, the success function ...

Incorporate PrimeNG into an Angular2 application with the help of Webpack

I've been trying to integrate PrimeNG into my Angular2 application bundled with Webpack. To start, I executed the following npm commands: npm install primeng --save npm install primeui --save This updated my package.json with the following entries: ...

What could be causing one of my images to not appear on my Gatsby page?

Hey there, I could use some help with this issue: Recently, I created a website using Gatsby.js and deployed it to my web server (which is running NGINX on Ubuntu 20.04). The site uses Gatsby Image for querying and displaying images, and everything seems t ...

Error: The render function in ReactJS components did not return anything

While attempting to create a new component and call it within App.jsx (another component) for rendering, an error is being encountered. Error: Error: App(...): Nothing was returned from render. This usually means a return statement is missing. Or, to rend ...

Utilizing TypeScript typing with the Express Request object

Encountering an issue with Typescript typings involving the Express Request object. The project is comprised of 2 sub-projects, the user-service and a common project containing reusable Errors and Middlewares. The common folder is added as a dependency in ...

Switching function handlers between elements in the d3 DOM framework

I have developed a piece of code that is designed to transfer event handlers from one element to another while removing them from the previous control. You can see the functionality in action on this fiddle: http://jsfiddle.net/pydty4bq/ var slider = d3.s ...

"Troubleshooting the issue of Angular's ViewContainerRef.createComponent malfunctioning on subsequent

My application is structured into Header, Context, and Content sections. I am looking to dynamically inject different components into the Context Component (viewContainerRef) based on the route and other conditions. To achieve this functionality, I have ...

The ScrollToTop feature in MUI component seems to be malfunctioning when paired with the useScrollTrigger hook

I am in the process of developing a custom ScrollToTop component using MUI's useScrollTrigger hook. More information can be found at this link Feel free to check out the sample code here: https://codesandbox.io/s/stackoverlow-mui-usescrolltrigger-er9 ...

javascript: separate string into parts and substitute values

I woke up with a terrible hangover after celebrating my birthday yesterday. Can someone please provide a simple and straightforward JavaScript function to help me split a string and replace the necessary values? Keep it simple, stupid (KISS)! Here's ...

Is it possible to utilize Angular's dependency injection in place of RequireJS?

As a newcomer to Angular, I am wondering how I can organize my code into separate files without using requirejs or any other framework. After watching a brief introductory video, it seemed possible. Currently, my app looks like this and functions well: v ...

Unable to establish a connection to a particular database and collection within the MongoDB Atlas Cluster

I am in the process of developing a MERN stack application and have opted to utilize mongoose for communication with MongoDB Atlas. However, I am facing difficulty in understanding how to connect to a specific database and collection within MongoDB Atlas d ...

Testing the value of an input in Angular using unit tests

Currently, I am delving into the official documentation of Angular2 which focuses on unit testing (https://angular.io/docs/ts/latest/guide/testing.html). My struggle lies in setting a component's input field value so that it reflects in the component ...

Get started with adding a Typescript callback function to the Facebook Login Button

I am in the process of implementing Facebook login into my Angular7 application using Typescript. Although I have successfully integrated Facebook's Login Button plugin for logging in, I am facing issues with providing a callback method to the button& ...

How to properly format text in C++ to transmit data as a JSON object

Currently, I am developing a node module in C++ that exchanges data using JSON objects. One specific issue I encountered involves reading CSV lines into C++: // example.csv description;This is a "text" containing all sorts of symbols: Ü€ễ ...

Angular factory transforming service

I am looking to transform the 'i18n' function into a factory in order to return a value instead of just setting it. Any suggestions or tips would be greatly appreciated! services.factory('i18nFactory', function() { var language = ...

Exploring the process of updating the background color of a specific component in Angular

I'm currently working on a website that will feature alternating colors of white and black. However, I am facing an issue where I can only apply background color changes globally in the CSS file. Does anyone know how to address this problem? ...

Getting the height of a div in a Nuxt.js application results in an error alert being displayed

Trying to retrieve the height of a div within a grid in a Nuxt application. <template> <div class="grid grid-cols-3"> <client-only> <Item v-for="( item, itemIndex ) in ItemsArray" ...