Lucas Gasenzer
Lucas Gasenzer

Reputation: 25

First entry of first entry of json

I am trying to select a specific entry from a JSON but can not solve how to do it. The JSON that I get from the server (can not be modified) is:

[{"cid":"PWER","data":[{"1458496671000":464}],"sid":"728834","units":"kWm","age":0}]

What I need to get is the 464 (Power in Watts). The problem is, that the key is a timestamp and changes all the time. So far I tried

json[0].data[0]

but this leaves me with

{ '1458496779000': 464 }

Any ideas how I select the next value?

Thanks a lot!

Upvotes: 0

Views: 26

Answers (1)

Bikas
Bikas

Reputation: 2759

You can do this -

var obj = json[0].data[0];
var key = Object.keys(obj)[0];
var data = obj[key];
// data is your value which should be 464.

Upvotes: 1

Related Questions