Is there a way to retrieve the specific dates from the json data?

{"version":0,"weights":[{"date":1528038188489,"weight":106.6},{"date":1528499328455,"weight":104.9},{"date":1528641180585,"weight":106.0},{"date":1528799825943,"weight":104.8},{"date":1531126307411,"weight":107.6},{"date":1531601049953,"weight":106.8},{"date":1531885441817,"weight":108.4},{"date":1536024680696,"weight":105.5},{"date":1539578290537,"weight":103.5},{"date":1539829328962,"weight":102.9},{"date":1540010784415,"weight":102.5},{"date":1540096742826,"weight":102.3},{"date":1540181346367,"weight":102.7},{"date":1541925087295,"weight":106.3},{"date":1542281158478,"weight":106.3},{"date":1542996044848,"weight":108.6},{"date":1543028073487,"weight":108.3},{"date":1543216891819,"weight":107.8},{"date":1543679231916,"weight":108.8},{"date":1543805932731,"weight":108.1},{"date":1543921648545,"weight":107.4},{"date":1544000057821,"weight":107.9},{"date":1544595979799,"weight":109.5},{"date":1544768651138,"weight":109.1},{"date":1544951465287,"weight":108.3},{"date":1545124493025,"weight":110.1},{"date":1545207092551,"weight":110.8},{"date":1545308566108,"weight":111.3},{"date":1545428287608,"weight":110.3},{"date":1546021373835,"weight":110.8}]}

I use an application to track my body weight and I can save the data as a .json file. Is there an easy way to extract the actual dates from the entries provided above without knowing much about JavaScript or JSON formats?

UPDATE: After some research, I discovered that the time in these entries is UNIX time. No further assistance needed. Thank you! However, I'm interested in learning more about UNIX time in general.

Answer №1

The complexity of the query may exceed the breadth of information provided here. Essentially, the task involves importing or parsing this particular object and iterating through the weights array with some form of date assessment, such as utilizing new Date(). Below is a simplified example in JavaScript to assist you in initiating the process. (In NodeJS, JSON files can be imported using require).

const myJSON = require('./thisJSON.json');

const myDates = myJSON.weights.map((weight) => new Date(weight.date));

// myDates
//['2018-06-03T15:03:08.489Z', '2018-06-03T15:03:08.489Z']

Answer №2

Get familiar with moment.js library: https://momentjs.com/

data = JSON.parse('{"version":0,"weights":[{"date":1528038188489,"weight":106.6},{"date":1528499328455,"weight":104.9},{"date":1528641180585,"weight":106.0},{"date":1528799825943,"weight":104.8},{"date":1531126307411,"weight":107.6},{"date":1531601049953,"weight":106.8},{"date":1531885441817,"weight":108.4},{"date":1536024680696,"weight":105.5},{"date":1539578290537,"weight":103.5},{"date":1539829328962,"weight":102.9},{"date":1540010784415,"weight":102.5},{"date":1540096742826,"weight":102.3},{"date":1540181346367,"weight":102.7},{"date":1541925087295,"weig...
    
var firstWeightDate = moment(data.weights[0].date)
firstWeightDate.format("dddd, MMMM Do YYYY, h:mm:ss a");
// "Monday, June 4th 2018, 1:03:08 am"

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

Each time a page loads, the react useContext feature is causing the web socket connection to reset

I have integrated websockets into various parts of my nextJS application and need to make sure they are accessible everywhere without resetting the socket connection. Whenever the connection is reset, it loses all the rooms it was connected to, causing iss ...

sending information back to a middleware using a resolved promise

As a newcomer to nodejs, I am facing an issue with retrieving data from a function that returns a promise. The response from the middleware needs to be sent back to the front end. Below is the relevant code snippet: // Middleware app.get('/player&apo ...

Attach the JSON data to the dropdown menu using jQuery

On my asp.net website, I have generated a JSon string using the JavaScriptSerializer class in JavaScript. Then, I displayed the Json string within the HTML markup by utilizing the RegisterStartupScript method and here is how it appears: This is the C#.net ...

Monitor the automatic redrawing system of mithril.js

I am considering using mithril.js to develop a high-performance application that will involve managing thousands of DOM elements that may need frequent updates. It is crucial for me to ensure that only the necessary elements are redrawn when changes occur. ...

How to incorporate subtitles in React Player?

I am facing an issue with adding subtitles in the React Player component. Below is the code snippet for the React Player component: <ReactPlayer url={vidData.media[0]} controls={true} width={"100%"} he ...

Having trouble getting DeviceOrientationControls to function properly

For the past week, I've been attempting to use my smartphone's orientation controls to manipulate my three.js scene. Although I lost the tutorial that originally guided me, I managed to find the example I saved from it. However, despite studying ...

Optimal timing for fulfilling promises in AJAX requests

Recently, I've delved into the world of promises to handle multiple ajax calls without knowing in advance how many will be required. In my journey, I came across these valuable posts: jQuery Deferred - waiting for multiple AJAX requests to finish jQu ...

Filtering input based on its occurrence rate (enable/disable debounce)

Utilizing node on a raspberry pi and the module onoff to capture input. I am interested in running function B only if function A is triggered twice within one minute. var gpio = require('onoff').Gpio; var sensor = new gpio(7, 'in', &ap ...

React is failing to display identical values for each item being mapped in the same sequence

I have implemented some standard mapping logic. {MEMBERSHIPS.map((mItem, index) => ( <TableCell className="text-uppercase text-center" colSpan={2} padding="dense" ...

Is there a way to convert a JSON Array into a CSV format with row names

I'm struggling with converting this JSON array to a CSV format. [relatedProducts] => Array ( [0] => 111001 [1] => 111002 [2] => 111007 [3] => 111021 [4] => 111022 [5] => 111024 [6] => 111027 [7] ...

Avoiding URL images on 404 errors in frontend applications

My goal is to dynamically implement images (from image_url_1.jpg to image_url_5.jpg) based on a specific URL. While everything works fine, I encounter an issue when a particular image, like "image_url_4.jpg," is not available and results in a 404 Error cau ...

What is the best approach for managing a One-to-One JSON loop?

My application features a class called "User" with an attribute that points to another user. The issue I'm facing is that one user has another user as their attribute, creating a loop. This situation differs from the typical scenario where one class h ...

Transforming data into a flat JSON format using jq

Currently, I am dealing with JSON data that needs to be inserted into a SQL database. This particular data is sourced from Google Cloud Firestore. Here is the input: { "0": { "filed1": "xxxx", "field": "zzzz" }, "1": { "field1": "xxx", ...

What is the best way to extract data from a nested JSON file and access information from a dataframe within another dataframe using

After receiving a json file as a response from an api, I noticed that it is nested and when visualized in a dataframe/table format, there are instances of data frames within data frames. The file has been stored at a location on github. library(tidyverse) ...

What is the best way to create a selection input using buttons and save the chosen option in the state?

Check out this snippet showcasing 3 buttons const [role, setRole] = React.useState('') const [active, setActive] = React.useState(false) <Grid container spacing={1}> <Grid item xs={4}> <Button variant='plain&apos ...

Finding a quicker route to fulfill a commitment

When dealing with asynchronous behavior in a function, I often find myself creating a deferred and returning a promise. For example: var deferred = $q.defer(); //...some async operation return deferred.promise; However, sometimes I want to skip the async ...

Implementing long polling for private messaging in PHP's chat functionality

Can you help me with a question I have regarding my chat form on the HTML page? Here is the code for the form: <form action="../addchat.php" method="POST" enctype="multipart/form-data"> <textarea id="textarea" style="border- ...

Retrieving the Inner HTML content of a listing upon clicking its button

I need help with my code that involves displaying a list of places and allowing users to add individual places to a separate list. When a button is clicked, it should change the innerHTML of the list item to match the result. However, I'm facing an is ...

AngularJS - akin to "live updates" in HTTP requests

Currently, I am working with AngularJS 1.3 and my backend only supports HTTP requests (no WebSockets). What would be the most effective solution for achieving "real-time" data updates? I am currently using $interval to send an HTTP request every second, b ...

Unable to successfully send a JSON POST request from a React/axios frontend to a restify backend server

My restify setup looks like this: var restify = require('restify'); const server = restify.createServer(); //server.use(restify.plugins.acceptParser(server.acceptable)); // [1] server.use(restify.plugins.queryParser()); server.use(restify.plug ...