When trying to use the Strava API with wattages per second I keep running into the problem of the first value always being null instead of a number.
struct streamsElement: Decodable {
struct Stream: Decodable {
let data: [Double]?
let series_type: String
let original_size: Int
let resolution: String
}
//decoding
if let wattsData = streams.watts?.data {
for watts in wattsData {
wattsArr.append("watts: \(watts)" )
}
}
"watts":{"data":[
null,
144,
98,
95, etc.
This works fine for all the other streams.
Error
Error decoding JSON data: valueNotFound(Swift.Double, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "watts", intValue: nil), CodingKeys(stringValue: "data", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "Expected Double but found null value instead.", underlyingError: nil))
How can i turn this Null value into a zero so I don't get a JSON decoding error?
I tried to skip the first value in the decoding but this did not work.