Skip to content

Extract values from array inside json #337

Closed Answered by larsga
koder29406 asked this question in Q&A
Discussion options

You must be logged in to vote

There's a few different ways you can deal with observations. The big question is: is the order reliable? It probably isn't.

You need to first find the observation that has "air_temperature", and only afterwards can you get the value. Try this:

[for (.observations) .value if (.elementId == "air_temperature")]

It will get you an array. Now you need to pick out the first element from it. Unfortunately, you can't just tack on a [0].

let air_temperatures = [for (.observations) .value if (.elementId == "air_temperature")]
$air_temperatures[0]

will do it.

Put the two lets at the top and you'll have it.

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@koder29406
Comment options

@larsga
Comment options

Answer selected by koder29406
Comment options

You must be logged in to vote
1 reply
@larsga
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
support Users asking how to solve a specific issue
2 participants